122: CS2 --- Assignment 4

Due Friday, May 19

Problem Description: An important ADT with many applications in computer science is the queue ADT. A queue is a First-In First-Out (FIFO) list. Elements are added (i.e., enqueued) at one end of the list called the rear and deleted (i.e., dequeued) from the other end called the front. This project involves implementing the queue ADT using linked lists. A header file for the class Queue has been defined for you. The header file for this class is

queue.h.

To test your queue you can use the following simple client program which inputs integers (until a negative integer is encoutered) and enqueues them as they are input. The program then dequeues the elements from the queue and displays them in the order they are dequeued.

testqueue.cpp.

Your client program for this assignment will be an enhancement of Program 3. In addition to the features implemented in Program 3, Program 4 will allow the user to display the distance matrix D, where D[i][j] is the distance from i to j, i.e., the length of a shortest path joining i and j. If there is no such path, i.e., i and j are disconnected, then by convention we will set D[i][j] = n, where n denotes the number of nodes of the network. Note that the maximum possible length of a shortest path is n - 1. The distance matrix and its computation using queues will be discussed in detail in class.

You should modify files network.h and network.cpp to include the auxillary function

Distance()

that computes and returns a two-dimensional vector representing the distance matrix D.

Your client program will include both the header files "queue.h" and "network.h". As in Program 3, your client program will begin by prompting the user for the name of the file where the network data is stored. It should then call the ExtractTo function to initialize the network object. Following this the program will display the (adjacency matrix of the) initial network using the operator <<. The rest of the program will be menu driven with the following menu:

1. Add a new link
2. Remove a link
3. Add a new node
4. Remove a node
5. Display network
6. Display distance matrix
7. Exit program

When displaying the distance matrix replace the value n in each entry i,j where it occurs (indicating that i and j are disconnected) with the symbol -.