void doubleArray (int array[],int s) { for (int i = 0; i < s; i++) array[i] = ar
ID: 3815268 • Letter: V
Question
void doubleArray (int array[],int s)
{
for(int i = 0; i < s; i++)
array[i] = array[i]*2 ;
}
void selectionSort (int array[], int s)
{
int largestIndex ; // index of largest number
int temp; //temporary holds largest number
for(int last = s - 1 ; last >= 1 ; last --)
{
largestIndex = 0 ;
for(int i = 0; i <= last; i++)
{
if(array[i] > array[largestIndex])
largestIndex = i ;
}
temp = array[largestIndex ];
array[largestIndex] = array[last];
array[last] = temp;
}
}
Explanation / Answer
HI, Please find my working selection Sort in decreasing order:
void selectionSort(int arr[], int n)
{
int i, j, max_idx;
// One by one move boundary of unsorted subarray
for (i = 0; i < n-1; i++)
{
// Find the maximum element in unsorted array
max_idx = i;
for (j = i+1; j < n; j++)
if (arr[j] > arr[max_idx])
max_idx = j;
// Swap the found maximum element with the first element
int temp = arr[max_idx];
arr[max_idx] = arr[i];
arr[i] = temp
}
}
THis is correct:
void doubleArray (int array[],int s)
{
for(int i = 0; i < s; i++)
array[i] = array[i]*2 ;
}
Please let me know if still you are facing problem
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.