All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class edu.vt.marian.common.QuickSort

java.lang.Object
   |
   +----edu.vt.marian.common.QuickSort

public class QuickSort
extends Object
A quicksort object which can be used to sort the elements of an enumeration in either non-increasing or non-decreasing order. The only requirement is that each element of the object being sorted implements the Sortable interface. Basically, this means an object provides a compare() method which can be used to determine whether one object is less than, equal to, or greater than another object.


Variable Index

 o objects
Vector holding the elements of the object being sorted whilst they are sorted in-place.
 o sortIncreasing
Flag to indicate whether we are performing a non-decreasing sort (true) or a non-increasing sort (false)

Constructor Index

 o QuickSort(Enumeration, int)
Make a new object to quicksort the supplied enumeration.

Method Index

 o elements()
Return an enumeration containing the elements contained in this object in sorted order.
 o quicksort(int, int)
The classic quicksort algorithm.

Variables

 o objects
 protected Vector objects
Vector holding the elements of the object being sorted whilst they are sorted in-place.

 o sortIncreasing
 protected boolean sortIncreasing
Flag to indicate whether we are performing a non-decreasing sort (true) or a non-increasing sort (false)

Constructors

 o QuickSort
 public QuickSort(Enumeration elts,
                  int sortType)
Make a new object to quicksort the supplied enumeration. The constructor copies the elements of the enumeration to a local vector, so they can be sorted in-place. It also keeps track of the desired type of sort (non-increasing or non-decreasing).

Parameters:
elts - the enumeration to be sorted
sortType - the type of order in which to sort: Sortable.INCREASING or Sortable.DESCREASING.
See Also:
Sortable, Vector, Enumeration

Methods

 o elements
 public Enumeration elements()
Return an enumeration containing the elements contained in this object in sorted order. Basically, this method simply invokes quicksort on the local vector, and then returns an enumeration of the objects in that vector after quicksort has sorted them.

Returns:
an enumeration of the sorted objects
See Also:
elements
 o quicksort
 protected void quicksort(int start,
                          int end)
The classic quicksort algorithm. This version is implemented from pseudocode provided in Cormen, Lieserson, and Rivest, _Introduction to Algorithms_, Chapter 8: Quicksort, p. 154.

Parameters:
start - the start of the portion of the vector to be sorted
end - the end of the portion of the vector to be sorted

All Packages  Class Hierarchy  This Package  Previous  Next  Index