public List<V> topolocigalSort(V root) {

		Set<V> visited = new HashSet<>();
		List<V> ordered = new ArrayList<>();

		Deque<VertexChildIterator> stack = new ArrayDeque<>();

		stack.push(new VertexChildIterator(root));
		visited.add(root);

		while (!stack.isEmpty()) {
			VertexChildIterator childIterator = stack.getFirst();
			if (childIterator.hasNext()) {
				V child = childIterator.next();

				// only process the child if never seen before, otherwise it is a loop back
				if (!visited.contains(child)) {
					stack.push(new VertexChildIterator(child));
					visited.add(child);
				}
			}
			else {
				ordered.add(childIterator.getParent());
				stack.pop();
			}
		}
		Collections.reverse(ordered);
		return ordered;
	}
Sorts the vertices in this graph topologically.

@param root the start node for traversing the graph (will always be the first node in the
resulting list)
@return a list of vertices reachable from the given root vertex, sorted topologically
Ghidra/Framework/Graph/src/main/java/ghidra/graph/GraphToTreeAlgorithm.java