Re:Sort an array

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re:Sort an array

Martin Lafaix

> From: [hidden email]
> How to code a sort to obtain the following result:
> Sort by country then name.

Depending on your dataset (i.e., size, distribution, etc.),

Either (1) sort on country, then on name (using a sort that
preserve relative order for the second iteration) or (2) use a
single sort, with a comparator function like:

  -- return 1 if c1 should precede c2, 0 otherwise
  method isLessThan(c1 = Customer, c2 = Customer)
    if c1.country < c2.country then return 1
    if c1.country = c2.country then return c1.name < c2.name
    return 0

To choose the best solution to your problem, check for example The
Art of Computer Programming, Volume 3 (Sorting and Searching).


Martin
--
[hidden email]
Team OS/2
http://www.mygale.org/~lafaix

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>