APCS Java Subset

ap
Class ListQueue

java.lang.Object
  extended byap.ListQueue
All Implemented Interfaces:
Queue

public class ListQueue
extends java.lang.Object
implements Queue

A simple yet completely functional implementation of the Queue interface. The interface is part of the AP subset and is testable. This implementation is not part of the subset, but is useful in a classroom setting.

All queue functions execute in O(1) or constant time amortized over several queue operations. This is because the underlying storage is java.util.LinkedList which supports constant time access, add (to end and front), and remove (from end and front).

This implementation is provided at apcentral.


Constructor Summary
ListQueue()
          Constructs an initially empty queue.
 
Method Summary
 java.lang.Object dequeue()
          Dequeues and returns the first element of the queue.
 void enqueue(java.lang.Object x)
          Enqueue an element onto the back of this queue.
 boolean isEmpty()
          Returns true if this queue is empty, otherwise returns false.
 java.lang.Object peekFront()
          Returns the first element of the queue without dequeuing it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListQueue

public ListQueue()
Constructs an initially empty queue.

Method Detail

enqueue

public void enqueue(java.lang.Object x)
Description copied from interface: Queue
Enqueue an element onto the back of this queue.

Specified by:
enqueue in interface Queue
Parameters:
x - is the object enqueued onto this queue.

dequeue

public java.lang.Object dequeue()
Description copied from interface: Queue
Dequeues and returns the first element of the queue.

Specified by:
dequeue in interface Queue
Returns:
the just-dequeued element of the queue
See Also:
Queue.peekFront()

peekFront

public java.lang.Object peekFront()
Description copied from interface: Queue
Returns the first element of the queue without dequeuing it.

Specified by:
peekFront in interface Queue
Returns:
the first element of the queue
See Also:
Queue.dequeue()

isEmpty

public boolean isEmpty()
Description copied from interface: Queue
Returns true if this queue is empty, otherwise returns false.

Specified by:
isEmpty in interface Queue
Returns:
true if this queue is empty, otherwise return false.

unofficial documentation for the APCS Java Subset