weiss.util
Class PriorityQueue<AnyType>

java.lang.Object
  extended by weiss.util.AbstractCollection<AnyType>
      extended by weiss.util.PriorityQueue<AnyType>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<AnyType>, Collection<AnyType>, Queue<AnyType>

public class PriorityQueue<AnyType>
extends AbstractCollection<AnyType>
implements Queue<AnyType>

PriorityQueue class implemented via the binary heap.

See Also:
Serialized Form

Constructor Summary
PriorityQueue()
          Construct an empty PriorityQueue.
PriorityQueue(Collection<? extends AnyType> coll)
          Construct a PriorityQueue from another Collection.
PriorityQueue(Comparator<? super AnyType> c)
          Construct an empty PriorityQueue with a specified comparator.
 
Method Summary
 boolean add(AnyType x)
          Adds an item to this PriorityQueue.
 void clear()
          Make this PriorityQueue empty.
 AnyType element()
          Returns the smallest item in the priority queue.
 Iterator<AnyType> iterator()
          Returns an iterator over the elements in this PriorityQueue.
 AnyType remove()
          Removes the smallest item in the priority queue.
 int size()
          Returns the number of items in this PriorityQueue.
 
Methods inherited from class weiss.util.AbstractCollection
contains, equals, hashCode, isEmpty, remove, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface weiss.util.Collection
contains, isEmpty, remove, toArray, toArray
 

Constructor Detail

PriorityQueue

public PriorityQueue()
Construct an empty PriorityQueue.


PriorityQueue

public PriorityQueue(Comparator<? super AnyType> c)
Construct an empty PriorityQueue with a specified comparator.


PriorityQueue

public PriorityQueue(Collection<? extends AnyType> coll)
Construct a PriorityQueue from another Collection.

Method Detail

add

public boolean add(AnyType x)
Adds an item to this PriorityQueue.

Specified by:
add in interface Collection<AnyType>
Overrides:
add in class AbstractCollection<AnyType>
Parameters:
x - any object.
Returns:
true.

size

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

Specified by:
size in interface Collection<AnyType>
Returns:
the number of items in this PriorityQueue.

clear

public void clear()
Make this PriorityQueue empty.

Specified by:
clear in interface Collection<AnyType>
Overrides:
clear in class AbstractCollection<AnyType>

iterator

public Iterator<AnyType> iterator()
Returns an iterator over the elements in this PriorityQueue. The iterator does not view the elements in any particular order.

Specified by:
iterator in interface java.lang.Iterable<AnyType>
Specified by:
iterator in interface Collection<AnyType>
Returns:
an iterator positioned prior to the first element.

element

public AnyType element()
Returns the smallest item in the priority queue.

Specified by:
element in interface Queue<AnyType>
Returns:
the smallest item.
Throws:
NoSuchElementException - if empty.

remove

public AnyType remove()
Removes the smallest item in the priority queue.

Specified by:
remove in interface Queue<AnyType>
Returns:
the smallest item.
Throws:
NoSuchElementException - if empty.