public Iterator<Node> getBreadthFirstIterator(boolean directed) { LinkedList<Node> l = new LinkedList<Node>(); Iterator<Node> it; elementLock.lock(); sg.elementLock.lock(); it = wrappedElement.getBreadthFirstIterator(directed); while (it.hasNext()) l.add(sg.getNode(it.next().getIndex())); sg.elementLock.unlock(); elementLock.unlock(); return l.iterator(); }
public Iterator<Node> getBreadthFirstIterator(boolean directed) { LinkedList<Node> l = new LinkedList<Node>(); Iterator<Node> it; elementLock.lock(); sg.elementLock.lock(); it = wrappedElement.getBreadthFirstIterator(directed); while (it.hasNext()) l.add(sg.getNode(it.next().getIndex())); sg.elementLock.unlock(); elementLock.unlock(); return l.iterator(); }
/** * Determines if a graph is (weakly) connected. * * @param graph A graph. * @return {@code true} if the graph is connected. * @complexity O({@code m + n}) where {@code m} is the number of edges and {@code n} is the number of nodes. */ public static boolean isConnected(Graph graph) { if (graph.getNodeCount() == 0) return true; Iterator<Node> it = graph.getNode(0).getBreadthFirstIterator(false); int visited = 0; while (it.hasNext()) { it.next(); visited++; } return visited == graph.getNodeCount(); } }
/** * Determines if a graph is (weakly) connected. * * @param graph A graph. * @return {@code true} if the graph is connected. * @complexity O({@code m + n}) where {@code m} is the number of edges and {@code n} is the number of nodes. */ public static boolean isConnected(Graph graph) { if (graph.getNodeCount() == 0) return true; Iterator<Node> it = graph.getNode(0).getBreadthFirstIterator(false); int visited = 0; while (it.hasNext()) { it.next(); visited++; } return visited == graph.getNodeCount(); } }