in reply to Sorting problem
Sounds like you need Dijkstra's Algorithm for graph searching; the order in which it visits those nodes should be the order you're looking for.
In Section
Seekers of Perl Wisdom
in reply to Sorting problem
Sounds like you need Dijkstra's Algorithm for graph searching; the order in which it visits those nodes should be the order you're looking for.