Sort in the Descending Orger with Index

Discussion in 'Java' started by Luigi Napolitano, Dec 17, 2004.

  1. 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
     
    Luigi Napolitano, Dec 17, 2004
    #1
    1. Advertising

  2. Thomas Weidenfeller, Dec 17, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Chatham

    Ascending & Descending sort in datagrid

    Steve Chatham, Feb 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,900
    =?Utf-8?B?U3VyZXNo?=
    Feb 19, 2004
  2. Luigi Napolitano

    Sort in descending order with index

    Luigi Napolitano, Dec 17, 2004, in forum: C++
    Replies:
    2
    Views:
    3,100
    Luigi Napolitano
    Dec 17, 2004
  3. Luigi Napolitano

    Sort in the Descending Order

    Luigi Napolitano, Dec 17, 2004, in forum: C Programming
    Replies:
    7
    Views:
    381
  4. sudhir
    Replies:
    8
    Views:
    828
    Kenny McCormack
    Dec 6, 2005
  5. Clinto

    Selection Sort in descending order HELP!!

    Clinto, Oct 21, 2007, in forum: C Programming
    Replies:
    4
    Views:
    1,892
    Clinto
    Oct 21, 2007
Loading...

Share This Page