Question: 14.2 So far weve implemented graphs as adjacency matrices or adjacency lists. Another approach is to use Java references to represent edges, so that a

14.2 So far weve implemented graphs as adjacency matrices or adjacency lists. Another approach is to use Java references to represent edges, so that a Vertex object contains a list of references to other vertices that its connected to. In a directed graph a reference used this way is especially intuitive because it points from one vertex to another. Write a program that implements this scheme. The main() method should be similar to main() in the path.java program (Listing 14.2) so that it creates the graph shown in Figure 14.6 using the same addVertex() and addEdge() calls. It should then display a connectivity table of the graph to prove that the graph is constructed properly. Youll need to store the weight of each edge somewhere. One approach is to use an Edge class, which stores its weight and the vertex on which it ends. Each vertex then keeps a list of Edge objectsthat is, edges that start on that vertex.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!