Graph Data Structure and Algorithms Lab One

©1999 Northeastern University

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.
Start by just printing out the vertex indices and names.
Then print information from the edge lists.


3. Make the destructor. Put in a message to show each edge before it is deleted
// destructor
~Graph(){
// Very Important:  You must remove the edge lists>
// The vertex array will be automatically removed

};
4. Implement the DrawGraph() member function.
It is easiest to work on the vertices first. When they show up in the right places, work on the edges and weights. In the final version, the edges must be drawn before the weights and vertices.
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

Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #161CN,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/COM1101/HW/PROG/GraphLab1.html