Question: Program C++ I want to use the quicksort algorithm below to sort by using the first element to compare againt other and put in descending

Program C++

I want to use the quicksort algorithm below to sort by using the first element to compare againt other and put in descending order. So if the number is less than the first element move it to the right and greater than move to the left. All numbers should be compared against the same elment which is the first element.

int partition(int *a,int p,int r) { int q = p-1, i; //First Element int temp = 0; int pivot = a[0];

for (i = p; i < r; i++) { if (a[i] >= a[r]) //descending or acsending (change greater/less than sign) { ++q; temp = a[q]; a[q] = a[i]; a[i] = temp; } }

++q;

temp = a[q]; a[q] = a[r]; a[r] = temp;

return q;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!