public void DFS() {

        final int rootNode = 0;
        final Stack<Integer> stack = new Stack<Integer>();
        stack.push(rootNode);
        visited[rootNode] = true;
        printNodes(rootNode);
        while (!stack.isEmpty()) {
            // using peek is because there might be lots of unvisited child nodes, so we shouldn't remove the node
            // yet.We
            // only remove it if there is no child node anymore
            final int n = stack.peek();
            final int child = getUnvisitedChildNode(n, g);
            if (child != -1) {
                visited[child] = true;
                printNodes(child);
                stack.push(child);
            } else {
                stack.pop();
            }
        }
        clearVisited(visited);
    }