CS331

Assignment #4

Programming

In this assignment you will carry out tests to compare the two class Queue implementations discussed in your text in Section 3.4. One implementation must employ the linked implementation of class List, while the other must use an array.

Consider the following plan for carrying out your tests.

You will need to download several files from the author's Web site.

http://www.cs.fiu.edu/~weiss/dsaa_c++/code/

Get QueueAr.cpp as well as the associated header file and test driver program. For the linked list implementation, you will need his linked list class, linkedlist.cpp and its header file, from which you can implement class Queue by private derivation. Since Weiss uses his dsexceptions.h in the list, you will also need that file. As discussed in the text, he also provides a vector class. You can download and use it, or use the one in the Standard Library.

Create a Visual C++ project for each queue and get the test driver program working. These tests should confirm that the enqueue, dequeue, isFull and isEmpty  functions work as expected.

For your timing tests, enqueue n integers and then dequeue n integers, measuring the total time using the clock() function. Try it for values of n in the range of 10,000 to 100,000. If this time is too small for meaningful reporting, i.e., less than a second, you can put the entire operation in a loop that gets executed m times, reporting the total time, e.g.,

Start = clock();
For(k=0;k<m;k++){
    // loop to enqueue
    for(i = 0, i<n;i++)
        q.enqueue(i);
    // loop to dequeue
    while( queue is not empty)
        x = q.dequeue();
}
Finish = clock()

After testing one of the queues, you should be able to use the same driver program for testing the other one since the class interface should be the same.

Tabulate your results in a spreadsheet. In a single plot show the run times vs. n for both queues. Discuss your results, explaining what your tests reveal. For example, do the results  confirm the theoretical performance for the queues? Aside from the asymptotic (large n) performance, how do the implementations perform for low values of n?

Finally, discuss the implementation of the two queues. For example, how does each implementation deal with changes in needed queue capacity at execution time?  In the case of the list implementation, why should it be a private derivation?