Due Dates:
Queues, deques, and priority queues are data abstractions that serve multiple purposes. For example, a Queue is often used in breadth-first search, which in turn applies to a variety of artificial intelligence problems. A deque will be used in a future video game we will develop, and a priority queue has uses in the realm of simulation.
Requirement: Implement classes Queue and Deque using your own linked list implementation. Your implementation should be “from scratch”. This would border on trivial if you were allowed to use standard Java libraries, such as LinkedList and Vector, so we don’t allow you to use them.
The Queue implementation will count for 25% and the Deque implementation for 75%.
The Queue implementation provides a stepping stone for the Deque.
Clearly you could do Deque first and specialize to Queue, but you are discouraged
to take this route. Instead implement a Queue without any of the additional
mechanism required for Deque. Also, the Deque should be easier once you’ve done
the Queue, but if you have problems with the Queue, you would certainly have
problems if you did the Deque first.
Extra credit: Implement class PriorityQueue.
·
void enqueue(Object)
·
Object dequeue()
· boolean isEmpty()
·
void enqueueFront(Object)
·
Object dequeueBack()
·
void enqueueBack(Object)
· Object dequeueFront()
· boolean isEmpty()
·
void enqueue(Comparable)
·
Comparable dequeueMin()
· boolean isEmpty()
Throw an EmptyQueueException in the case of attempting to dequeue
from an empty Queue or Deque.
|
File |
Purpose |
Provider |
Queue.java |
Queue
interface |
Me |
Deque.java |
Deque
interface |
You |
PriorityQueue.java |
Priority
queue interface |
(You,
E.C.) |
MyQueue.java |
Queue
implementation |
You |
EmptyQueueException.java |
Exception for any of your classes. |
You |
MyDeque.java |
Deque
implementation |
You |
MyPriorityQueue.java |
Priority
queue implementation |
(You,
E.C.) |
TestQueue.java |
Queue
test implementation |
Me |
TestDeque.java |
Deque
test implementation |
Me |
TestPriorityQueue.java |
Priority
queue test implementation |
Me |
Construct each type of queue from an inner class Cell. You need not take pains to keep access to the components of Cell private, as Cells will only be used inside of the queue, not outside. So the data are already encapsulated in a sense.
I strongly encourage you to use a box diagram for reasoning about the method codings, especially for the Deque implementation. If you come in for help with null pointer exceptions, please have a box diagram with you to show your rationale.
You may wish to implement a toString method for each class, so that you can print out the contents of your object for debugging purposes.
Comment your code. Be sure your comments indicate what each method does, including what the inputs and outputs are. For non-obvious methods, comment how it works as well.
Compile and run the self contained test java sources, e.g.:
java
TestQueue
You should submit your rex functions in two files: Quantity.java and OpenList.java using
cs60submit MyQueue.java EmptyQueueException.java . . .
where . . . represents any other supported.java files needed. Do NOT submit .class files or test files.