Lab 2 will allow you to get some familiarity with linked lists. You will re-implement the graph class using an adjacency list format instead of an adjacency matrix. Once you're done, you will use the Intro-CS Assignment Dropoff form to hand in your finished program.
Download the lab2.zip file from the 15-113 course web site. Save the zip file to your temp directory and unzip the files. You should see the following files:
Open the lab2.mcp file and look at the filenames listed inside. If you open up the graph-main-2.cpp file, you'll notice that it no longer includes graph-adj.h, but now includes graph-list.h. You should copy your graph-adj files from lab1 into the lab2 folder and then rename your graph-adj.h to graph-list.h and graph-adj.cpp to graph-list.cpp. You should then add graph-list.cpp to your project file.
struct Edge { int dest; double cost; Edge* next; Edge(int d = -1, double c = 0, Edge* link = NULL) : dest(d), cost(c), next(link) {} };Once you've changed the private data member, you should see what changes this causes in the declarations of the member functions (in particular, the one-parameter constructor). Then it's on to the implementation of all the member functions! Inside the renamed graph-list.cpp, you will need to change the #include "graph-adj.h" to #include "graph-list.h" and then you will need to modify the implementations of the member functions.
As in the Adjacency Matrix implementation, you may NOT assume that an edge is not already present between the two vertices in your new implementation of AddEdge (if it is, overwrite its cost with the new value) and you may NOT assume that an edge is in the graph in your new implementation of RemoveEdge. Your code should behave analagously to that which was present in the Adjacency Matrix implementation. Also, you MUST delete any edges that are removed by RemoveEdge().
You should make no changes to graph-main-2.cpp! When you've completed your re-implementation of the Graph class, graph-main-2.cpp will exercise your implementation. To run your program, open a DOS window, cd into the directory where you're working and type the following command: 113.exe graph.txt. This time, since we're removing some edges, the correct answers are
Your Solution zip file must contain (only) the following files
Use the Intro Programming dropoff form to submit your zip file.