Sort in the Descending Orger with Index

L

Luigi Napolitano

Hello,

I use this algorithm to sort an array "v" in the descending order.

void quickSort(float v[], int lo0, int hi0)
{
int lo = lo0;
int hi = hi0;
if (lo >= hi) return;
float mid = v[(lo + hi) / 2];

while (lo < hi)
{
while (lo<hi && v[lo] > mid) lo++;
while (lo<hi && v[hi] < mid) hi--;
if (lo < hi) swap(v,lo, hi);
}

if (hi < lo) swap(v, hi, lo);

quickSort(v, lo0, lo);
quickSort(v, lo == lo0 ? lo+1 : lo, hi0);
}

I would like to have an array "index" to order another array "z".

Example:
v = [ 5, 9, 7 ]
index = [ 1, 2, 0 ]
z = [ 1, 2, 3 ]

so...
for (i = 0; i<=2; i++)
cout<<z[index];
Output: [ 2, 3, 1 ]

I would like to have index = [ 1, 2, 0 ]. How?
Thanks to everybody.

Luigi Napolitano
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,039
Members
48,768
Latest member
first4landlord

Latest Threads

Top