rendered paste body private static void bfs(UndirectedGraph g, int f, int t) throws IOException{ queue.offer(new Integer(f)); boolean found = false; boolean nopath = false; while(!found || !nopath){ if(graph.degree(f)>0){ int tmp = queue.remove(); visit(tmp); if(graph.areAdjacent(tmp, t)){ //Print the path found = true; }else{ VertexIterator tmp2 = graph.adjacentVertices(tmp); while(tmp2.hasNext()){ queue.add(tmp2.next()); } } }else{ System.err.println("No path from : " + f + "to " +t); nopath = true; } } }