Opus5
Class LeftistHeap
java.lang.Object
|
+--Opus5.AbstractObject
|
+--Opus5.AbstractContainer
|
+--Opus5.AbstractTree
|
+--Opus5.BinaryTree
|
+--Opus5.LeftistHeap
- All Implemented Interfaces:
- Comparable, Container, MergeablePriorityQueue, PriorityQueue, Tree
- public class LeftistHeap
- extends BinaryTree
- implements MergeablePriorityQueue
A node of a mergeable priority queue implemented as a leftist tree.
- Version:
- $Id: LeftistHeap.java,v 3.6 1998/09/23 13:00:00 brpreiss Exp $
- Author:
- Bruno R. Preiss, P.Eng.
| Methods inherited from class Opus5.BinaryTree |
attachKey, attachLeft, attachRight, compareTo, depthFirstTraversal, detachKey, detachLeft, detachRight, getDegree, getKey, getLeft, getRight, getSubtree, isEmpty, isLeaf, purge |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
nullPathLength
protected int nullPathLength
- The null path length.
LeftistHeap
public LeftistHeap()
- Constructs an empty
LeftistHeap.
LeftistHeap
public LeftistHeap(Comparable key)
- Constructs a
LeftistHeap that contains the specified key.
swapSubtrees
protected void swapSubtrees()
- Swaps the subtres of this node.
merge
public void merge(MergeablePriorityQueue queue)
- Merges the contents of the specified mergeable priority queue
with this leftist heap.
It is assumed that the specified priority queue is
a
LeftistHeap instance.
After merging the contents,
the specified queue is empty.
- Specified by:
merge in interface MergeablePriorityQueue
- Parameters:
queue - The queue to merge with this one.
enqueue
public void enqueue(Comparable object)
- Enqueues the specified object in this leftist heap.
- Specified by:
enqueue in interface PriorityQueue
- Parameters:
object - The object to enqueue.
findMin
public Comparable findMin()
- Returns the "smallest" object in this leftist heap.
The smallest object in this leftist heap
is the object that is less than or equal to
all other objects in this leftist heap.
- Specified by:
findMin in interface PriorityQueue
- Returns:
- The "smallest" object in this leftist heap.
- Throws:
ContainerEmptyException - If this leftist heap is empty.
dequeueMin
public Comparable dequeueMin()
- Dequeues and returns the "smallest" object in this leftist heap.
The smallest object in this leftist heap
is the object that is less than or equal to
all other objects in this leftist heap.
- Specified by:
dequeueMin in interface PriorityQueue
- Returns:
- The "smallest" object in this leftist heap.
- Throws:
ContainerEmptyException - If this leftist heap is empty.