http://qs1969.pair.com?node_id=1083932


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.