## CS 2401 Assignment #8

Due Date: Wednesday, July 25, 2012.

Objective: The goal of this assignment is to practice the use of queues.

Assignment: In many Olympic competitions such as high jump, athlete wait in a line to show their skills. Let us emulate this line.

Your simulation will simulate a 20 minutes interval. Each high jump may require several attempts, so it takes between 1 and 3 minutes to complete. New competitors arrive over time, with some randomness. In your simulation, the number of new competitors that arrive on each time step will vary between 0 and 1. To execute the simulation, at each moment of time, perform the following steps:

• Generate new competitors and add them to the queue. First, generate a random number (using Math.random()) between 0 and 1 to see how many competitors to add. If one competitor was selected, generate a random number between 1 and 3 for each competitor to determine how many minutes this competitor will take. Enqueue this number.
• For the competitor at the head of the queue -- the one who is jumping right now -- decrement the number of minutes by 1. If the value becomes 0, this indicates that the competitor finished jumping. In this case, remove this competitor from the queue (if the queue was empty, it remains empty).
We are interested in two important values: the average length of the queue of competitors, and the maximum length of the queue. Your program should compute these values. Repeat simulations 100 times and compute the average and maximum over all these simulations. Write the code of the main part of the program so that the code only uses the ADT operations enqueue, dequeue, size, and isEmpty. Then, show that your program works with both types of queue implementation -- as a linked list and as an array.