/** An instance of a class that implements this interface represents a queue ** capable of holding items of the specified type T (the generic type ** parameter). A queue is a container having a FIFO ("first-in-first-out") ** insertion/removal pattern. ** ** Author: R. McCloskey ** Date: January 2020 */ public interface Queue { // observers // --------- /** Returns the number of items on this queue. */ int sizeOf(); /** Returns true iff there are no items on this queue. */ boolean isEmpty(); /** Returns true if this queue fails to have the capacity to store ** any more items (i.e., enqueue() would fail), false otherwise. */ boolean isFull(); /** Returns (a reference to) the item at the front of this queue. ** pre: !this.isEmpty() */ T frontOf(); // mutators // -------- /* Removes all the items from this queue, leaving it empty. ** post: isEmpty() */ void clear(); /** Places the specified item onto the rear of this queue. ** pre: !isFull() ** post: Letting elem(k) refer to the k-th item on a queue, counting ** from the front starting at zero, and letting q refer to this ** queue before enqueue() is applied: ** this.sizeOf() = q.sizeOf() + 1 && ** this.elem(q.sizeOf()) = item && ** for all k satisfying 0 <= k < q.sizeOf(), this.elem(k) = q.elem(k) */ void enqueue(T item); /** Removes the item at the front of this queue and returns ** (a reference to) it. ** pre: !isEmpty() ** post: Letting elem(k) refer to the k-th item on a queue, counting ** from the front starting at zero, and letting q refer to this ** queue before dequeue() is applied: ** this.sizeOf() = q.sizeOf() - 1 && ** for all k satisfying 0 <= k < this.sizeOf(), this.elem(k) = s.elem(k+1) */ T dequeue(); }