Velocity Reviews > Java > Sort in the Descending Orger with Index

# Sort in the Descending Orger with Index

Luigi Napolitano
Guest
Posts: n/a

 12-17-2004
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[i]];
Output: [ 2, 3, 1 ]

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

Luigi Napolitano

Thomas Weidenfeller
Guest
Posts: n/a

 12-17-2004
Luigi Napolitano wrote:
> for (i = 0; i<=2; i++)
> cout<<z[index[i]];
> Output: [ 2, 3, 1 ]

This is C++. Try a C++ group.

/Thomas

--