200201202203204205206207208209210
q.add(startVertex); while (!q.isEmpty()) { Vertex vertex = q.poll(); for (Vertex neighbor : neighborsForVertex.get(vertex)) { if (!subgraph.contains(neighbor)) { subgraph.addVertex(neighbor); q.add(neighbor); } } } return subgraph;