For this homework assignment, modify the directed graph code given in Figure 16.1 (Digraph.h) in the book. The modifications are as follows:
list<int> adjacencyList
, you will need a list of Edge classes.
The edge class will contain an integer for the index of the endpoint and an
integer for the weight of the edge. You will also need to modify any code
that refers to the adjacency list so that it properly accesses the endpoint
index.
read()
to read from a comma-seperated file.
Currently the read
function reads from a file like NetworkFile
shown in Figure 16.2. Modify it to read from a file that has the following
format:
node value, endpoint1 weight1, endpoint2 weight2, ... , endpointN weightNFor example:
Los Angeles, 3 7, 4 12 San Francisco, 3 10, 1 2, 4 7 Denver, 1 8, 2 7 Chicago, 2 9, 3 2, 1 10
typename
as described in
Lab 6 in order to compile it on Helios.
Welcome to the Directed Graph menu ---------------------------------------------- 1. Read in a directed graph from a file 2. Do a depth-first search 3. Do a breadth-first search 4. Compute the shortest path between two nodes 5. Print the directed graph 0. Exit ----------------------------------------------For option 1, prompt the user for a filename, open the file and then call the
read
function on that file.
For options 2 and 3, prompt the user for the index of the starting node and then perform the search from that starting node. If the whole graph cannot be searched from that node, select an unprocessed node at random and repeat the search until all the nodes have been processed.
For option 4, prompt the user for the index of the starting node and the index of the destination node. Call the shortest path function with these two nodes. Print out the shortest path if the destination can be reached or "destination not reachable" if it cannot.
For option 5, call the display
function.