/** * Removes the given vertex from the given graph. If the vertex to be removed has one or more * predecessors, the predecessors will be connected directly to the successors of the vertex to * be removed. * * @param graph graph to be mutated * @param vertex vertex to be removed from this graph, if present * @param <V> the graph vertex type * @param <E> the graph edge type * * @return true if the graph contained the specified vertex; false otherwise. */ public static bool removeVertexAndPreserveConnectivity <V, E>(Graph <V, E> graph, V vertex) { if (!graph.containsVertex(vertex)) { return(false); } if (vertexHasPredecessors(graph, vertex)) { List <V> predecessors = Graphs.predecessorListOf(graph, vertex); List <V> successors = Graphs.successorListOf(graph, vertex); foreach (V predecessor in predecessors) { addOutgoingEdges(graph, predecessor, successors); } } graph.removeVertex(vertex); return(true); }