CS 112
Homework 7
Due: Wednesday 3/29/2000 by 12:00 a.m.


The Problem, general description

First year Smith students are waiting in line to get their orientation package. The process is slow and tedious, because the packages are organized by id numbers, while the students arrive in random order. So the assistants have to move piles of packages to get to the one currently being requested. To speed things up, it was decided to sort the first 20 students in the queue, according to their id, as soon as the queue gets bigger than 20. Then process the lot of 20, and repeat.

Your task is to write (part of) the software to assist with this process.

Overview of what to implement

There are two important parts of this homework, recursion and queues.

First, you have to implement the Quicksort algorithm, for sorting an array of integers in a recursive manner. Then you have to extend the Queue class we started in the lab on Thursday with a function for sorting the queue, using Quicksort.

Details

Your program should be organized as a class (IntQueue) for the queue operations, and a testdriver (testQueue) for performing the desired operations on the queue. The testdriver should have the (by now very familiar) menu-driven interface, allowing the user to add and remove items from the queue, test how big the queue is, print or sort the queue.

As you can see, for testing purposes I simplified the specifications of the original problem. For extra credit, you can also implement the original task of sorting only the first 20 students in the queue. The specification on how to do this is left to you. If you do the extra credit part, you should notify me by email.

The IntQueue class should have: a constructor, a function to add an element in the queue called In and a function to get an element out of the queue called Out. Notice that these names are different from those used in the book. It should also have a function to return the number of elements in the queue, to test if the queue is empty or full, and a Print function to be used for testing purposes. The queue has to be implemented as a circular queue.

In addition to this basic structure, it should contain a function called Sort for sorting the queue using QuickSort, implemented recursively.

References

The book has, on page 250, a full program for QuickSort, implemented as a template - which is more general than what I am asking you to do. I do not want you to copy the code from the book! You should go over the code, understand it, then implement your own version ONLY for an array of integers.

Chapter 4 has the Queue Abstract data type, which you should use as reference, but implement the queue EXACTLY as I specified above. Your queue should contain only integers and be called IntQueue.

To submit

Submit in hw7 all the files: sources, Makefile, a typescript and a data file with your test data. See below for naming conventions.
Naming conventions and files to submit (in hw7):

Ileana Streinu