public static void BFS_Visit(Vertex<Integer> u) { Deque<Vertex<Integer>> q = new LinkedList<>(); q.add(u); while (!q.isEmpty()) { Vertex<Integer> v = q.poll(); v.setMarkState(Graph.VISIT_COLOR_GREY); for (Edge<Integer> x : v.getOutgoingEdges()) { Vertex<Integer> ver = x.getTo(); if (ver.getMarkState() == Graph.VISIT_COLOR_WHITE) { if (ver.getData() != 0) ver.setData(v.getData() + 1); ver.setParent(v); q.add(ver); } } v.setMarkState(Graph.VISIT_COLOR_BLACK); } }
public void clearState() { for (Vertex<T> x : vertices) x.setMarkState(VISIT_COLOR_WHITE); }