Interface PriorityQueue<Element extends java.lang.Comparable>

All Superinterfaces:
java.lang.Iterable<Element>
All Known Implementing Classes:
ArrayPriorityQueue

public interface PriorityQueue<Element extends java.lang.Comparable>
extends java.lang.Iterable<Element>

A PriorityQueue represents an unbounded queue of items arranged in some priority order. This queue orders items according to their natural order (see Comparable). A priority queue does not permit null elements. A priority queue also does not permit insertion of non-comparable objects (doing so may result in ClassCastException).
The head of this queue is the greatest element with respect to the specified ordering. If multiple elements are tied for greatest value, the head is one of those elements -- ties are broken arbitrarily. The queue retrieval operations dequeue and peek access the element at the head of the queue.
All implementations must include an iterator() method to allow clients to use for-each loop to traverse the elements of the PriorityQueue in order.

Version:
09/29/2007
Author:
J. Dalbey

Method Summary
 void clear()
          Removes all elements from the priority queue.
 Element dequeue()
          Retrieves and removes the head of this queue.
 void enqueue(Element element)
          Adds the specified element to this priority queue.
 boolean isEmpty()
          Indicates whether or not the queue is empty.
 Element peek()
          Retrieves, but does not remove, the head of this queue.
 int size()
          Returns the number of elements currently in this queue.
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

clear

void clear()
Removes all elements from the priority queue.


peek

Element peek()
Retrieves, but does not remove, the head of this queue.

Returns:
the head item in the queue, or null if this queue is empty.

dequeue

Element dequeue()
Retrieves and removes the head of this queue.

Returns:
the head item in the queue, or null if this queue is empty.

enqueue

void enqueue(Element element)
Adds the specified element to this priority queue.

Parameters:
element - is an item to be enqueued
Precondition:
element is not null

size

int size()
Returns the number of elements currently in this queue.

Returns:
int the size of the queue

isEmpty

boolean isEmpty()
Indicates whether or not the queue is empty.

Returns:
true if the queue size is zero, false otherwise.