forked from anku580/Java-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEulerTour.java
More file actions
44 lines (35 loc) · 902 Bytes
/
EulerTour.java
File metadata and controls
44 lines (35 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public class EulerTour {
private int[] degree;
EulerTour(Graph g, int s) {
degree = new int[g.V()];
int count;
for (int i = 0; i < g.V(); i++) {
count = 0;
for (int w : g.adj(i)) {
count++;
}
degree[i] = count;
}
}
int findingEulerPath(Graph g) {
for (int j = 0; j < g.V(); j++) {
if (degree[j] % 2 == 1)
return 0;
}
return 1;
}
public static void main(String args[]) {
Graph g = new Graph(4);
g.addEdge(0, 1);
g.addEdge(0, 3);
g.addEdge(1, 3);
g.addEdge(1, 2);
EulerTour e = new EulerTour(g, 0);
int res = e.findingEulerPath(g);
if (res == 0) {
System.out.println("No");
} else {
System.out.println("Yes");
}
}
}