in reply to Exceptional sorting

How would you sort:
@ar = (1245, 1247, 0000, 1246, 1248)
Should 0000 remain between 1245 and 1246, or should it remain between 1247 and 1248? It can't do both.

Abigail

Replies are listed 'Best First'.
Re: Re: Exceptional sorting
by PerlingTheUK (Hermit) on May 25, 2004 at 10:49 UTC
    0000 should remain between 1245 and 1246.
    @ar = ( 1245, 0000, 1246, 1247, 1248 );
    after sorting.
      Why? Why not between 1247 and 1248? If you don't say why 0000 stays between certain numbers, I'd have to ask 120 questions to be able to sort a set of five numbers.

      Abigail

        It is times. Station a: (sorted)
        {Train 0 => 1230, Train 1 => 1244, Train 2 => 1245 , Train 3 => 1247 }
        Station b: Train 3 does not stop here, so time is 0000. But I know it is following Train 1.
        {Train 1 => 1245, Train 2 => 0000 , Train 3 => 1248 }
        I will take the existing order of trains, and calculate the next station.
        But trains can be overtaken by other trains in which case I will have a time for the train. So if as station c Train 1 overtakes Train 3 but Train 2 has no time the array would be { Train 0 => 1245, Train 1 => 1255, Train 2 => 0000, Train 3 = 1250 }. In that case my sorting needs to set Train 1at the end, while the other trains need to be kept in order. It is not 5 entries but a couple of 100000s of times that need to be sorted.