public void DFS(Node<T> n, Set<Node<T>> visited, ArrayList<T> sorted) {
		if ( visited.contains(n) ) return;
		visited.add(n);
		if ( n.edges!=null ) {
			for (Node<T> target : n.edges) {
				DFS(target, visited, sorted);
			}
		}
		sorted.add(n.payload);
	}
DFS-based topological sort.  A valid sort is the reverse of
 the post-order DFA traversal.  Amazingly simple but true.
 For sorting, I'm not following convention here since ANTLR
 needs the opposite.  Here's what I assume for sorting:

   If there exists an edge u -&gt; v then u depends on v and v
   must happen before u.

 So if this gives nonreversed postorder traversal, I get the order
 I want.
tool/src/org/antlr/v4/misc/Graph.java