Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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


 
Reply With Quote
 
 
 
 
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

--
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to sort the data present in file in ascending or descending order sudhir C Programming 8 12-06-2005 03:06 PM
Sort in the Descending Order Luigi Napolitano C Programming 7 12-22-2004 03:32 PM
Sort in descending order with index Luigi Napolitano C++ 2 12-17-2004 10:49 PM
descending sort on files in 'save as' dialogue NewB Computer Support 6 11-05-2004 07:43 AM
Ascending & Descending sort in datagrid Steve Chatham ASP .Net 2 02-19-2004 09:31 PM



Advertisments