private JungDirectedGraph<V, E> createTree(V root, List<V> sorted, Map<V, Depth> depthMap) {
		Set<V> visited = new HashSet<>();
		visited.add(root);

		JungDirectedGraph<V, E> tree = new JungDirectedGraph<V, E>();
		for (V v : sorted) {
			tree.addVertex(v);
		}

		for (V parent : sorted) {
			Depth parentDepth = depthMap.get(parent);
			Collection<E> outEdges = graph.getOutEdges(parent);
			for (E e : outEdges) {
				V child = e.getEnd();
				if (visited.contains(child)) {
					continue;  // already assigned
				}
				Depth childDepth = depthMap.get(child);
				if (childDepth.isDirectChildOf(parentDepth)) {
					tree.addEdge(e);
					visited.add(child);
				}
			}
		}
		return tree;
	}
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