next up previous


CSE 2320 Section 501/571 Fall 1999

Program 4

Due: November 23, 1999, 5:30pm (November 24, 1999, 5:00pm for -10%)

For this program you will implement a router that determines the shortest route for sending a message from one node to another in a network. The network will be read in from a file along with a series of message source and destination nodes. Your program will represent the network as a directed graph and print out the shortest route for each message, if a route exists. No global variables may be used. Specifically,

1.
Implement a directed graph data structure using the adjacency list representation. You will need procedures for allocating a graph, deallocating a graph, and adding a directed edge to the graph. The graph should be dynamically allocated to hold just the number of vertices (nodes) necessary.

2.
Implement a procedure for finding the shortest route between two nodes in the network. If there is more than one shortest route between nodes, your procedure should choose the one visiting the smaller-numbered node. Note that the route may not exist.

3.
The main part of your program will read in data from a file whose name is given as the first argument to your executable. The first line of the file contains the number of vertices (nodes) V and edges E in the graph. The next E lines define the edges of the graph in the form 'e 5 3', which means there is a directed edge in the graph from vertex 5 to vertex 3. You may assume the edge source and destination are different and valid. The remaining lines represent message requests in the form 'm 4 20', which means we desire to know the shortest route from node 4 to node 20. You may assume that the message source and destination are different and valid. Your main program should read in the network and then read in each message request, one at a time, outputting the shortest route, if any. See files pgm4in and pgm4out in the class directory on omega for an example. Your output should match the format of the example output.

4.
Follow the instructions from Program 1 for handing in the file containing all your source code using the program /public/cse/2320-501/handin4 on omega.


next up previous