Opus5
Class HeapSorter

java.lang.Object
  |
  +--Opus5.AbstractSorter
        |
        +--Opus5.HeapSorter
All Implemented Interfaces:
Sorter

public class HeapSorter
extends AbstractSorter

Sorter for sorting an array of Comparable objects. Implements heapsort.

Version:
$Id: HeapSorter.java,v 3.1 1998/07/28 01:32:17 brpreiss Exp $
Author:
Bruno R. Preiss, P.Eng.
See Also:
Comparable

Field Summary
protected static int base
          The first element of a heap has the number 1 (not zero).
 
Fields inherited from class Opus5.AbstractSorter
array, n
 
Fields inherited from interface Opus5.Sorter
copyright
 
Constructor Summary
HeapSorter()
           
 
Method Summary
protected  void buildHeap()
          Builds a heap from the unsorted array.
protected  void percolateDown(int i, int length)
          Percolates the object at position i in this heap down into the correct position.
protected  void sort()
          Sorts the array of comparable objects.
 
Methods inherited from class Opus5.AbstractSorter
sort, swap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base

protected static final int base
The first element of a heap has the number 1 (not zero).
Constructor Detail

HeapSorter

public HeapSorter()
Method Detail

percolateDown

protected void percolateDown(int i,
                             int length)
Percolates the object at position i in this heap down into the correct position.
Parameters:
i - The position of the object to be percolated down.
length - The length of the heap.

buildHeap

protected void buildHeap()
Builds a heap from the unsorted array.

sort

protected void sort()
Sorts the array of comparable objects.
Overrides:
sort in class AbstractSorter