package ap;
import java.util.LinkedList;
/**
* 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. */ public class ListQueue implements Queue { /** * Constructs an initially empty queue. */ public ListQueue() { list = new LinkedList(); } public void enqueue(Object x) { list.addLast(x); } public Object dequeue() { return list.removeFirst(); } public Object peekFront() { return list.getFirst(); } public boolean isEmpty() { return list.size() == 0; } private LinkedList list; }