Data Structures, Algorithms, & Applications in Java
Chapter 10, Exercise 9
The code is given below. The left end of the deque is the front
of the queue and the deque's right end is the rear of the queue.
public class DequeQueue extends ArrayDeque
implements Queue
{
// constructors
/** create a queue with the given initial capacity */
public DequeQueue(int initialCapacity)
{super(initialCapacity);}
/** create a queue with initial capacity 10 */
public DequeQueue()
{// use default capacity of 10
this(10);
}
// methods
/** @return front element of queue
* @return null if queue is empty */
public Object getFrontElement()
{return getLeftElement();}
/** @return rear element of queue
* @return null if the queue is empty */
public Object getRearElement()
{return getRightElement();}
/** insert theElement at the rear of the queue */
public void put(Object theElement)
{putAtRight(theElement);}
/** remove an element from the front of the queue
* @return removed element
* @return null if the queue is empty */
public Object remove()
{return removeFromLeft();}
}