private void search(Node root, AdjacencyList list, boolean forward){
        root.visited = forward;
        if(list.getAdjacent(root) == null){
            if(forward) stack.add(0, root);
            return;
        }
        for(Edge e : list.getAdjacent(root)){
            if(e.to.visited != forward){
                search(e.to, list, forward);
            }
        }
        if(forward) stack.add(0, root);
    }