in reply to Exceptional sorting

Your "new" sort order is not unique, or I don't understand the criteria used to sort. I think I can find two possible orders for your example:

1245 0000 1246 1247 1248 1245 1246 1247 1248 0000

Why is the second order not allowed? Is it because the 0000 was to the left of the 1246 ? If such is the case, I would make the elements so that they order "properly" by encoding them differently:

  1. Translate all elements by appending the "normal" marker. Let's define the "normal" marker as "n".
  2. For every element 0000n (a "normal 0"), replace that element by the element to the right of it, but omit the normal marker. In your example, the 0000n would become 1246.
  3. Let the normal Perl sort rip through your items.
  4. Convert all your items back to their old format.

Depending on your actual needs (for example, times wrapping around the day border), it might be more convenient to first convert all your "numbers" into seconds since the 1. January 1970, and then sort the times.

Replies are listed 'Best First'.
Re: Re: Exceptional sorting
by pelagic (Priest) on May 25, 2004 at 10:37 UTC
    > For every element 0000n (a "normal 0"), replace that element by the element to the right of it
    Do that only if the element to the right of it is not a '0000n' also.

    pelagic
      Most would be 0000n.