Solution: Removing an Edge
This review provides a detailed analysis of how to remove a given edge from a graph.
We'll cover the following...
Solution
Press + to interact
main.java
Graph.java
import java.io.*;import java.util.*;class Graph {private int vertices; //number of verticesprivate LinkedList < Integer > adjacencyList[]; //Adjacency Lists@SuppressWarnings("unchecked")// ConstructorGraph(int vert) {this.vertices = vert;this.adjacencyList = new LinkedList[vertices];for (int i = 0; i < this.vertices; ++i)this.adjacencyList[i] = new LinkedList();}// Function to add an edge into the graphvoid addEdge(int source, int destination) {this.adjacencyList[source].add(destination);//for undirected graph edge added from destination to source as wellthis.adjacencyList[destination].add(source);}public int getVertices() {return this.vertices;}public LinkedList < Integer > [] getAdj() {return this.adjacencyList;}public void dfsTraversal(int v, boolean visited[]) {visited[v] = true;int source = 0;Iterator < Integer > i = adjacencyList[v].iterator();Integer temp;while (i.hasNext()) {temp = i.next();if (!visited[temp])dfsTraversal(temp, visited);}}};
Explanation
This ...