The aim is to adapt the implementation of the AdjacencyListGraph class to support weights on edges.
The steps should be the following:
- Understand Snippet 6.1 showing how we can implement the adjacency list representation
- Adapt the implementation so that the array list can store the weights
ArrayList<Edge>[] adj;
public AdjacencyListWeightedGraph(int nodes) {
this.adj = new ArrayList[nodes];
for (int i = 0; i < nodes; i++)
this.adj[i] = new ArrayList<>();
}
public void addEdge(int u, int v, int weight) {
this.adj[u].add(new Edge(u, v, weight));
}
Snippet 6.2: Implementation of an adjacency list representation of a weighted graph. Source class name: Adjacencylistweightedgraph