Package cpsc331.collections
Class ListQueue<E>
- java.lang.Object
-
- cpsc331.collections.ListQueue<E>
-
-
Constructor Summary
Constructors Constructor Description ListQueue()
Creates a linked list representing an empty queue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
insert(E x)
Inserts a new object onto the queue.boolean
isEmpty()
Reports whether the queue is currently empty without changing it.E
peek()
Reports the front element of the queue without changing it.E
remove()
Removes an element from the front of the stack and reports it.
-
-
-
Method Detail
-
insert
public void insert(E x)
Description copied from interface:Queue
Inserts a new object onto the queue.- Specified by:
insert
in interfaceQueue<E>
- Parameters:
x
- the object to be pushed onto the queue
Precondition:
- The Queue Invariant is satisfied.
- An element x of type E has been given as input.
- The Queue Invariant is satisfied.
- The input object x has been inserted at the rear of the queue (which is otherwise unchanged).
-
peek
public E peek()
Description copied from interface:Queue
Reports the front element of the queue without changing it.
-
remove
public E remove()
Description copied from interface:Queue
Removes an element from the front of the stack and reports it.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Queue
Reports whether the queue is currently empty without changing it.- Specified by:
isEmpty
in interfaceQueue<E>
- Returns:
- true if the queue is empty, and false otherwise
Precondition:
- The Queue Invariant is satisfied.
- The Queue Invariant is satisfied.
- The queue is not changed.
- If the queue was empty before this operation then “true” is returned as output.
- If the queue was not empty before this operation then “false” is returned as output.
-
-