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

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

    multiple sorting of an array


    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. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    I would imagine that you would have to create your own sort routine.

    The easiest solution would be to use a database for this instead of a flat file.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Vienna, Austria
    Posts
    3
    Rep Power
    0
    Hi Onslaught,
    yes, i know! I know that a database handles this correctly and i know how i can do this. My problem is, that iīm working on a project, where i canīt use any databases or 3rd party addons to sort this datas. I must do it by myself - but how??

    I have made many experiments with different sort-algorithms, but i havenīt found any solution for my problem. I donīt need a complete program code, i only need a idea, how i can realize this problem.

    I see no way to solve it by myself ...
    Richard
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    Ok, lets brake this down.
    Lets look at this from the easiest sorting solution. You already know how to sort on one field easily enough, lets take that knowledge and apply it to multiple fields but, for a twist, do it as only one field.
    When you apply the sorting logic to the field, combine all of the ordering fields together into one string, delimited by whatever fashion you want, and send that to the sorting function.

    Does that make sense?
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Cyprus
    Posts
    4
    Rep Power
    0
    Originally posted by Onslaught
    Ok, lets brake this down.
    Lets look at this from the easiest sorting solution. You already know how to sort on one field easily enough, lets take that knowledge and apply it to multiple fields but, for a twist, do it as only one field.
    When you apply the sorting logic to the field, combine all of the ordering fields together into one string, delimited by whatever fashion you want, and send that to the sorting function.

    Does that make sense?
    In principle I agree with Onslaught but it is probably more ilegant and flexible to use a different function that will get the three (or actually the n) fields and return a single sort sequence value. One such function is what Onslaught is saying i.e. simply concanating the three values.

    In pseudo code most sorting algorithms look like something like this


    loop
    compare (a,b)
    re-order list according to results of comparison
    end loop

    where a,b are the values that are to being compared i.e. in most cases the values of some fields.

    There is nothing prohibiting of changing that to the return values of some functions.
    i.e. a = valueOf(a1,a2,...an)
    b = valueOf(b1,b2,....bn)

    valueOf can simply be a string concunacation or even something quite complex e.g. non-linear functions e.t.c

    Hope this helps more

    Thomas

IMN logo majestic logo threadwatch logo seochat tools logo