non-recursive topological sort

vg blew the stack when sorting a 1mb graph.