Objectives
Build a graph class to:
a.
Create an adjacency list representation of a graph from a data file.
b.
Draw the graph from the data structure.
First
Run GraphDraw with one of the data files. It doesn't do anything but load the file
then construct, write, draw, and destruct the graph.
Run ColorGrapher on several data files for inspiration and to see how the algorithms
work.
Overview
You will first implement some parts of the Graph class
in Graph.h
The constructor is already there. It creates an empty vertex list with space for
63 vertices. (I picked 63 = 7x9 so the drawing window wouldn't get too cluttered.)
Your job:
1.
Read the data in from a data file. You must build linked lists of edges. The order
doesn't matter. You may just insert at the head as you build the lists.
void ReadGraph(){
// Look at FileTools.h to see how to Select a file name and open a data file
// Use the "textread" mode to read the ASCII data files
// precondition: Assume a proper graph file
// postcondition: The adjacency list data structure exists
// Open the file
// Read vertices
// Read edges
// Close the file
};
2.
Implement the WriteGraph() member function. // destructor
~Graph(){
// Very Important: You must remove the edge lists>
// The vertex array will be automatically removed
};
4.
Implement the DrawGraph() member function. void DrawGraph(){
// Draw the graph
// Here are some sample calls to the Draw functions
// Draw.DrawEdge(3, 5, 1, 7, 2, BlueShade(200));>
// draws a blue edge with pensize 2x2 grid from position (3, 5) to (1, 7)
// Draw.ShowWeight(3, 5, 1, 7, 12);
// Shows the weight 12 in the middle of the edge
// Draw.DrawVertex(vertices[v], RedShade(200), false);
// draws the vth vertex - comes out green with red number and edge
};
Last Updated: April 4, 1999 8:48 am by