public Stack<DirectedNode> topologicalSort(DirectedNode root) {
        //uses dfs, and then places each visited node onto a stack. This stack when emptied, comprises of
        //the only or first found permutation of possible topological sorts
        Stack<DirectedNode> visitedNodes = new Stack<DirectedNode>();
        Stack<DirectedNode> topologicalNodes = new Stack<DirectedNode>();

        visitedNodes.push(root);
        root.visited = true;
        while (!visitedNodes.isEmpty()) {
            DirectedNode curNode = visitedNodes.pop();
            topologicalNodes.push(curNode);
            for (DirectedNode node : curNode.edgeNodes) {
                if (!node.visited) {
                    node.visited = true;
                    dfs(node);
                    visitedNodes.push(node);
                }
            }
        }
        return topologicalNodes;
    }