Q:

(Find shortest paths) Write a program that reads a connected graph from a file. The graph is stored in a file using the same format specified in Programming Exercise 29.9

0

 (Find shortest paths) Write a program that reads a connected graph from a file. The graph is stored in a file using the same format specified in Programming Exercise 29.9.Your program should prompt the user to enter the name of the file then two vertices, and should display a shortest path between the two vertices. For example, for the graph in Figure 29.23, a shortest path between 0 and 1 can be displayed as 0 2 4 3 1. Here is a sample run of the program:

Enter a file name: WeightedGraphSample2.txt

Enter two vertices (integer indexes): 0 1

The number of vertices is 6

Vertex 0: (0, 2, 3) (0, 1, 100)

Vertex 1: (1, 3, 20) (1, 0, 100)

Vertex 2: (2, 4, 2) (2, 3, 40) (2, 0, 3)

Vertex 3: (3, 4, 5) (3, 5, 5) (3, 1, 20) (3, 2, 40)

Vertex 4: (4, 2, 2) (4, 3, 5) (4, 5, 9)

Vertex 5: (5, 3, 5) (5, 4, 9)

A path from 0 to 1: 0 2 4 3 1

FIGURE 29.23 The WeightedNineTailModel class extends NineTailModel.

 

All Answers

total answers (0)

Similar questions


need a help?


find thousands of online teachers now