Answers for "depth first search for graphs java"

0

depth first traversal graph java

public void depthFirstSearch(Node node) {
    node.visit();
    System.out.print(node.name + " ");

    LinkedList<Node> allNeighbors = adjacencyMap.get(node);
    if (allNeighbors == null)
        return;

    for (Node neighbor : allNeighbors) {
        if (!neighbor.isVisited())
            depthFirstSearch(neighbor);
    }
}
Posted by: Guest on February-08-2021

Code answers related to "depth first search for graphs java"

Python Answers by Framework

Browse Popular Code Answers by Language