© 1998-2002 McGraw-Hill

structure
Interface PriorityQueue

All Known Subinterfaces:
MergeableHeap
All Known Implementing Classes:
VectorHeap, SkewHeap, PriorityVector

public interface PriorityQueue

Interface describing an queue of prioritized values. This linear-like structure has values that are inserted in such a way as to allow them to be removed in increasing order.

Example usage:

To print out a list of programmers sorted by age we could use the following:

 public static void main(String[] argv){
	//initialize a new fib heap
	PriorityQueue programmers = new FibHeap();

	//add programmers and their ages to heap
	//ages current of 7/22/2002
        programmers.add(new ComparableAssociation(new Integer(22), "Evan"));
	programmers.add(new ComparableAssociation(new Integer(19), "Chris"));
	programmers.add(new ComparableAssociation(new Integer(20), "Shimon"));
	programmers.add(new ComparableAssociation(new Integer(21), "Diane"));
	programmers.add(new ComparableAssociation(new Integer(21), "Lida"));	
	programmers.add(new ComparableAssociation(new Integer(20), "Rob"));	
	programmers.add(new ComparableAssociation(new Integer(20), "Sean"));	

	//print out programmers 
	while(!programmers.isEmpty()){
	    ComparableAssociation p = (ComparableAssociation)programmers.remove();
	    System.out.println(p.getValue() + " is " + p.getKey() + " years old.");
	}
 }
 


Method Summary
 void add(Comparable value)
          Add a value to the priority queue.
 void clear()
          Remove all the elements from the queue.
 Comparable getFirst()
          Fetch lowest valued (highest priority) item from queue.
 boolean isEmpty()
          Determine if the queue is empty.
 Comparable remove()
          Returns the minimum value from the queue.
 int size()
          Determine the size of the queue.
 

Method Detail

getFirst

public Comparable getFirst()
Fetch lowest valued (highest priority) item from queue.
Precondition:
!isEmpty()
Postcondition:
returns the minimum value in priority queue
Returns:
The smallest value from queue.

remove

public Comparable remove()
Returns the minimum value from the queue.
Precondition:
!isEmpty()
Postcondition:
returns and removes minimum value from queue
Returns:
The minimum value in the queue.

add

public void add(Comparable value)
Add a value to the priority queue.
Parameters:
value - The value to be added.
Precondition:
value is non-null comparable
Postcondition:
value is added to priority queue

isEmpty

public boolean isEmpty()
Determine if the queue is empty.
Postcondition:
returns true iff no elements are in queue
Returns:
True if the queue is empty.

size

public int size()
Determine the size of the queue.
Postcondition:
returns number of elements within queue
Returns:
The number of elements within the queue.

clear

public void clear()
Remove all the elements from the queue.
Postcondition:
removes all elements from queue

© 1998-2002 McGraw-Hill