org.apache.commons.collections
Class BinaryHeap

java.lang.Object
  |
  +--org.apache.commons.collections.BinaryHeap
All Implemented Interfaces:
PriorityQueue

public final class BinaryHeap
extends Object
implements PriorityQueue

Binary heap implementation of PriorityQueue.

Author:
Peter Donald, Ram Chidambaram

Constructor Summary
BinaryHeap()
           
BinaryHeap(boolean isMinHeap)
           
BinaryHeap(int capacity)
           
BinaryHeap(int capacity, boolean isMinHeap)
           
 
Method Summary
 void clear()
          Clear all elements from queue.
 void insert(Comparable element)
          Insert an element into queue.
 boolean isEmpty()
          Test if queue is empty.
 boolean isFull()
          Test if queue is full.
 Comparable peek()
          Return element on top of heap but don't remove it.
 Comparable pop()
          Return element on top of heap and remove it.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BinaryHeap

public BinaryHeap()

BinaryHeap

public BinaryHeap(boolean isMinHeap)

BinaryHeap

public BinaryHeap(int capacity)

BinaryHeap

public BinaryHeap(int capacity,
                  boolean isMinHeap)
Method Detail

clear

public void clear()
Clear all elements from queue.
Specified by:
clear in interface PriorityQueue

insert

public void insert(Comparable element)
Insert an element into queue.
Specified by:
insert in interface PriorityQueue
Parameters:
element - the element to be inserted

isEmpty

public boolean isEmpty()
Test if queue is empty.
Specified by:
isEmpty in interface PriorityQueue
Returns:
true if queue is empty else false.

isFull

public boolean isFull()
Test if queue is full.
Returns:
true if queue is full else false.

peek

public Comparable peek()
                throws NoSuchElementException
Return element on top of heap but don't remove it.
Specified by:
peek in interface PriorityQueue
Returns:
the element at top of heap
Throws:
NoSuchElementException - if isEmpty() == true

pop

public Comparable pop()
               throws NoSuchElementException
Return element on top of heap and remove it.
Specified by:
pop in interface PriorityQueue
Returns:
the element at top of heap
Throws:
NoSuchElementException - if isEmpty() == true

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2001 Apache Software Foundation. Documenation generated July 14 2001.