Problem

So far we’ve implemented graphs as adjacency matrices or adjacency lists. Another approach...

So far we’ve 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 it's 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. You'll 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 objects—that is, edges that start on that vertex.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 14
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT