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

Method bfs

Programs/FordFulkerson.java:9–32  ·  view source on GitHub ↗
(int Graph[][], int s, int t, int p[])

Source from the content-addressed store, hash-verified

7
8 // Using BFS as a searching algorithm
9 boolean bfs(int Graph[][], int s, int t, int p[]) {
10 boolean visited[] = new boolean[V];
11 for (int i = 0; i < V; ++i)
12 visited[i] = false;
13
14 LinkedList<Integer> queue = new LinkedList<Integer>();
15 queue.add(s);
16 visited[s] = true;
17 p[s] = -1;
18
19 while (queue.size() != 0) {
20 int u = queue.poll();
21
22 for (int v = 0; v < V; v++) {
23 if (visited[v] == false && Graph[u][v] > 0) {
24 queue.add(v);
25 p[v] = u;
26 visited[v] = true;
27 }
28 }
29 }
30
31 return (visited[t] == true);
32 }
33
34 // Applying fordfulkerson algorithm
35 int fordFulkerson(int graph[][], int s, int t) {

Callers 1

fordFulkersonMethod · 0.95

Calls 2

addMethod · 0.65
sizeMethod · 0.45

Tested by

no test coverage detected