Like this article? We recommend
Removing Edges from a Graph
Listing 5 illustrates the code to remove an edge.
Listing 5 Edge removal
void removeEdge(Edge e) { int v = e.v; int w = e.w; if (adjacencies[v][w] == true) { EdgeCount--; adjacencies[v][w] = false; } if (!digraph) { adjacencies[w][v] = false; } }
As you can see, it’s very similar to edge insertion. First, a test is made to determine whether the edge already exists. If it does, then the value of EdgeCount is decremented, and the associated entry in the adjacencies array is reset.
Finally, the test for a directional graph is made.
The easiest way to get a handle on graph processing is to see a complete example.