scranton.queue
Interface Queue

All Known Implementing Classes:
QueueViaArrayCirc, QueueViaLinear1Circ

public interface Queue

Specifications for a queue, the semi-formal notation for specifications appears on the notation page.

Specifications:
A queue, Q, is
  • Empty, Q = ()
  • Otherwise, Q = (a0, a1, ..., an-1), a0 is the front of the queue and an-1 is the rear

Initial Value:
Initial value: Q=()


Method Summary
 java.lang.Object dequeue()
          Decrease the size of the queue by one by removing and returning reference to the object that was at the front of the queue.
 void enqueue(java.lang.Object item)
          Increase the size of the queue by one by placing item as the rear of the queue.
 java.lang.Object frontOf()
          Queue does not change, returns the reference to the front object in the queue.
 boolean isEmpty()
          Queue does not change, returns true iff the queue is empty.
 java.lang.String toString()
          Returns a string representation of the queue.
 

Method Detail

isEmpty

public boolean isEmpty()
Queue does not change, returns true iff the queue is empty.

Specifications:
Q'=Q
Return Q==()

Returns:
boolean Q==().

frontOf

public java.lang.Object frontOf()
Queue does not change, returns the reference to the front object in the queue.

Specifications:
Q!=()
Q'=Q

Return a0

Returns:
Object Front of Queue.
Throws:
Assertion - When queue is empty

enqueue

public void enqueue(java.lang.Object item)
Increase the size of the queue by one by placing item as the rear of the queue.

Specifications:
Q'=(Q, obj)

Parameters:
item - The new rear of the queue

dequeue

public java.lang.Object dequeue()
Decrease the size of the queue by one by removing and returning reference to the object that was at the front of the queue. Note: The queue cannot be empty.

Specifications:
Q!=()
Q = (a0, Q')
Return: a0

Returns:
Object Front of queue.
Throws:
Assertion - When queue is empty

toString

public java.lang.String toString()
Returns a string representation of the queue. The format of the representation is "FRONT[Ofront\t...\tOrear]REAR"

Returns:
String representation of the queue