CS200 Lab 2—Implementing Queues
Overview
In this lab you will implement several Queues.
Files
Put these files in an Eclipse project:
Part 1: Queue
The Stack is from the example code from the first week’s lectures. You
need to implement the Queue, according to its interface. The instance
variables, constructor, and main method have been provided. Queue.java
does not compile. What do you need to do to make Queue.java work?
Do not implement your own linked list. Use the methods of the
LinkedList
type. If you find yourself allocating nodes and
setting references, then you’re doing it wrong.
Part 2: Circular Queue
Take the code in CQueue.java and create a circular queue.
- You will need to add instance variables.
- The constructor has an additional argument—the static size
of the circular queue.
- You must implement the circular queue using a fixed-size, ordinary
Java array. Using an ArrayList or a LinkedList is not permitted.
- If too many items are pushed on the circular queue, then the
newest item replaces the oldest item. Therefore, enqueue()
can’t throw an exception.
- However, dequeue() can throw an exception, as in part 1.