Due Monday, November 29, 11:59 P.M.
Reading: Chapters 12, pages 569 - 596.
The choice of methods for the graph classes is up to you. However you should have both private and public methods. To the extent you can, the private functions in each class should do the same tasks, only on different input formats. And to the extent you can the public functions should have the same definitions in the two cases, but use the private functions from their respective classes.
The graph algorithms should both be written once in your main program and not written twice in the in your two classes. These application functions should be called from main and should work (without changing them) for either the sequential or linked class. To do this they will have to access the (private) graph representations stored by the classes. And to do this they will need public class methods (auxiliary functions) which, for instance, takes a vertex as input and which outputs the next vertex adjacent to it that has not been visited. You may implement whatever auxiliary functions you like in your classes.
The output of the shortest path algorithm is only the LENGTH of the shortest path from vertex 1 to vertex n. It need not output the path itself.
A graph with n vertices will be a assumed to have vertices 1,2,3,4..., n. All weights are positive integers. You may assume that the graph has at most 40 nodes.
For example, a graph with three nodes and 2 edges, (1,3) of weight 11 and (2,3) of weight 33, might be given as
3 1 3 11 2 3 33Your main.cpp program will need to first call a function which input the graph from the datafile and which then prints out the graph. It should this by either printing out the adjacency array or by printing out the list of linked lists which store the graph.
The shortest path algorithm should find the length of the shortest path from vertex 1 to vertex n in the graph. (Vertex n is the highest numbered vertex.)
So you will need to run your program twice, once with the first graph class and once with the second graph class.
So a sample output might look like:
i. (The adjacency matrix of the graph here. )
ii. The Depth first search of the graph is: 1 5 3 6 7 2 4
iii. The shortest path from vertex 1 to vertex 7 has length 7.
You should input the data file using the UNIX command line and the redirection ("<") operator. When the program is tested it will be tested on other graphs, including unconnected graphs, graphs will only one node, and graphs with many cycles in them. SO make sure your program runs using the redirection operator.
Turn in your program file main.cpp.
Turn in your output in two output files, out_mat with the adjacency matrix output, and out_link, with the linked graph output. These files should contain the representation of the graph after it is stored and the output of the two algorithms on the graph.
You should also submit a text file called hw5.txt which documents the uses and capabilities of your program and how a user would run it. Finally you should write, use and submit a make file for this program.