MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / DFS

Method DFS

Programs/DFS.java:31–47  ·  view source on GitHub ↗
(int source)

Source from the content-addressed store, hash-verified

29
30
31 public void DFS(int source) {
32 //if the node is already visited, then backtrack.
33 if(this.visited[source] == true) {
34 return;
35 }
36 //mark the source vertex as visited
37 System.out.print(source+" ");
38 this.visited[source] = true;
39
40 //traverse through all the neighbours and backtrack if already visited.
41 LinkedList<Integer> neighbours = this.adj[source];
42
43 for(int next : neighbours) {
44 DFS(next);
45 }
46
47 }
48
49}
50

Callers 1

mainMethod · 0.95

Calls 1

printMethod · 0.80

Tested by

no test coverage detected