Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

The Significance of Listening

Answered: 1 week ago

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago