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

Method BFS

Programs/BreathFirstSearch.java:23–45  ·  view source on GitHub ↗
(int s)

Source from the content-addressed store, hash-verified

21
22 // BFS algorithm
23 void BFS(int s) {
24
25 boolean visited[] = new boolean[V];
26
27 LinkedList<Integer> queue = new LinkedList();
28
29 visited[s] = true;
30 queue.add(s);
31
32 while (queue.size() != 0) {
33 s = queue.poll();
34 System.out.print(s + " ");
35
36 Iterator<Integer> i = adj[s].listIterator();
37 while (i.hasNext()) {
38 int n = i.next();
39 if (!visited[n]) {
40 visited[n] = true;
41 queue.add(n);
42 }
43 }
44 }
45 }
46
47 public static void main(String args[]) {
48 Graph g = new Graph(4);

Callers 1

mainMethod · 0.95

Calls 3

printMethod · 0.80
addMethod · 0.65
sizeMethod · 0.45

Tested by

no test coverage detected