Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10. Rewrite the sorting algorithms BubbleSort(), SelectionSort() and InsertionSo

ID: 3919422 • Letter: 1

Question

10. Rewrite the sorting algorithms BubbleSort(), SelectionSort() and InsertionSort() (found on the class webpage in Examples/Lecture/C_Programs/SortingSearching/Sort.c) so that they sort in decreasing instead of increasing order.

Explanation / Answer

void BubbleSort(int* A, int n){ int i, j; for(j=n-1; j>0; j--){ for(i=1; iA[i-1] ){ swap(A, i, i-1); } } } } void SelectionSort(int* A, int n){ int i, j, imax; for(j=n-1; j>0; j--){ imax = 0; for(i=1; iA[i] ){ imax = i; } } swap(A, imax, j); } } void InsertionSort(int* A, int n){ int i, j, temp; for(j=1; j=0 && temp>A[i] ){ A[i+1] = A[i]; i--; } A[i+1] = temp; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote