public LinkedList BFS(UndirectedGraph g, int start, int goal) { Queue> routes = new ArrayDeque>(g.numVertices()); LinkedList vertices = new LinkedList(); vertices.add(new Integer(start)); while (!routes.isEmpty()) { LinkedList currentRoute = routes.poll(); int currentVertex = currentRoute.poll(); VertexIterator vi = g.adjacentVertices(currentVertex); while(vi.hasNext()) { int adjacentVertex = vi.next(); LinkedList newRoute; newRoute = currentRoute; newRoute.add(adjacentVertex); routes.add(newRoute); if(adjacentVertex == goal) { return newRoute; } } } return new LinkedList(); }