#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Vienna, Austria
    Posts
    3
    Rep Power
    0

    sortalgorithm of more than one column


    Hi,
    i search a possibility to sort an array with more than one key (like an ORDER BY X, Y in SQL). I have searched the whole internet after this information, but without any help ...

    I have a random-file, with more than 200.000 records. The quicksort-routine for one key is very fast and no problem. But i need more: I have 3 values

    ID,LAT,LONG

    And now i want to sort the LAT AND!!! the LONG values tougether, because some LAT values are equal.

    Hope i found here a answer of my question ... and a solution of my project (which is stopped since over a week, due this problem )

    Thanks,
    Richard
  2. #2
  3. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Italy -> Naples
    Posts
    9
    Rep Power
    0

    Lightbulb different sort


    U have to make a first sort on the first key, then u have to make a second sort on every subgroups generate with the second key and so on...
    An example:
    the initial matrix
    B 3 c
    C 2 c
    A 1 b
    A 3 a
    C 1 b
    C 3 a
    B 1 a
    B 2 b

    the matrix after the first sort using the first key
    A 1 b
    A 3 a
    B 3 c
    B 1 a
    B 2 b
    C 2 c
    C 1 b
    C 3 a

    the matrix after the second sort using the second key
    A 1 b
    A 3 a
    B 1 a
    B 2 b
    B 3 c
    C 1 b
    C 2 c
    C 3 a

    the final matrix after the third sort using the third key
    A 3 a
    A 1 b
    B 1 a
    B 2 b
    B 3 c
    C 3 a
    C 1 b
    C 2 c

    I hope that now u can restart to coding

IMN logo majestic logo threadwatch logo seochat tools logo