Class JavaPriorityQueue

java.lang.Object
  |
  +--JavaPriorityQueue
All Implemented Interfaces:
IPriorityQueue

public class JavaPriorityQueue
extends Object
implements IPriorityQueue

IPriorityQueue implementation using unsorted Java Vector objects to hold the keys and elements.


Field Summary
protected  Vector elements
          Elements in this.
protected  Vector keys
          Keys in this.
 
Constructor Summary
JavaPriorityQueue()
          Constructs a new unsorted priority queue.
 
Method Summary
 Object highest()
          Returns an object in this associated with a highest priority key.
 Comparable highestKey()
          Returns a highest priority key in this.
 void insertItem(Comparable key, Object element)
          Associates the given key and object and inserts them into this, increasing its size by 1.
 boolean isEmpty()
          Returns whether or not this is empty.
 Object removeHighest()
          Removes and returns the object in this associated with a highest priority key, reducing its size by 1.
 int size()
          Returns the number of items in this.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keys

protected Vector keys
Keys in this.


elements

protected Vector elements
Elements in this.

Constructor Detail

JavaPriorityQueue

public JavaPriorityQueue()
Constructs a new unsorted priority queue.

Method Detail

insertItem

public void insertItem(Comparable key,
                       Object element)
Associates the given key and object and inserts them into this, increasing its size by 1.

Specified by:
insertItem in interface IPriorityQueue
Parameters:
key - representation of priority for the element
element - object to store in this

removeHighest

public Object removeHighest()
Removes and returns the object in this associated with a highest priority key, reducing its size by 1.

Specified by:
removeHighest in interface IPriorityQueue
Throws:
RuntimeException - if this is empty

highestKey

public Comparable highestKey()
Returns a highest priority key in this.

Specified by:
highestKey in interface IPriorityQueue
Throws:
RuntimeException - if this is empty

highest

public Object highest()
Returns an object in this associated with a highest priority key.

Specified by:
highest in interface IPriorityQueue
Throws:
RuntimeException - if this is empty

size

public int size()
Returns the number of items in this.

Specified by:
size in interface IPriorityQueue

isEmpty

public boolean isEmpty()
Returns whether or not this is empty.

Specified by:
isEmpty in interface IPriorityQueue