Have you considered that this problem might not have a solution for some inputs? At least not with the rules that you have given us (as I understood them).
Consider these data records, already pre-sorted according to route distance.
ID = 5, Distance = 1,6, RouteDistance = 0
ID = 1, Distance = 1.7, RouteDistance = 2.5
ID = 2, Distance = 1.5, RouteDistance = 2.8
ID = 3, Distance = 2.3, RouteDistance = 4.3
IDs 1 2 and 3 are well sorted and need to stay in this order. Then, of course, the first line needs to be moved to be inserted somewhere else according to the Distance. But where are you going to insert it? Because IDs 1, 2 and 3 are not ordered for distance, it is not possible to insert ID 5 anywhere. For example, if you put it after ID 2, OK, it will be OK compared to ID 2 and 3, but it will be after ID 1, although its distance is smaller. Any other solution will fail likewise.
In reply to Re: Sorting an array of hashes with an exeption
by Laurent_R
in thread Sorting an array of hashes with an exception
by martin_87
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |