/** * Method testEulerian to check if the given graph is Eulerian or not. A Eulerian graph is * connected and the degree of each vertes is even. They have a cycle, that goes through every * edge of graph only once. A connected graph with exactly two vertices of odd degree has Eulerian * Path. * * @param g: Input graph which is to be tested for satisfying Eulerian conditions */ static int testEulerian(Graph<Vertex> g) { Vertex v1 = null, v2 = null; int conn = dfsUtil(g); if (conn > 1) { System.out.println("The graph is not connected."); System.exit(0); } int odd = 0; for (Vertex u : g) { if (u.Adj.size() % 2 != 0) { odd++; if (odd == 1) { v1 = u; } else if (odd == 2) { v2 = u; } } } if (odd == 0) { return 2; } else if (odd == 2) { System.out.println(v1 + " and " + v2); return 1; } else return 0; }