arlut.csd.Util
Class QuickSort

java.lang.Object
  |
  +--arlut.csd.Util.QuickSort
All Implemented Interfaces:
Compare

public class QuickSort
extends java.lang.Object
implements Compare

QuickSort implementation for Object array. Uses the Compare interface for item comparisons.

Algorithm from

Based on code by Eric van Bezooijen (eric@logrus.berkeley.edu) and Roedy Green (roedy@bix.com).


Field Summary
(package private)  Compare comparator
           
(package private)  java.lang.Object[] objects
           
 
Constructor Summary
QuickSort(java.lang.Object[] objects, Compare comparator)
           
 
Method Summary
 int compare(java.lang.Object a, java.lang.Object b)
          Default comparator, does a string comparison on the toString() output of the objects for ordering.
private  int partition(int first, int last)
          Partition by splitting this chunk to sort in two and get all big elements on one side of the pivot and all the small elements on the other.
private  void quick(int first, int last)
           
 void sort()
           
private  void swap(int i, int j)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

objects

java.lang.Object[] objects

comparator

Compare comparator
Constructor Detail

QuickSort

public QuickSort(java.lang.Object[] objects,
                 Compare comparator)
Method Detail

quick

private void quick(int first,
                   int last)

partition

private int partition(int first,
                      int last)

Partition by splitting this chunk to sort in two and get all big elements on one side of the pivot and all the small elements on the other.


swap

private void swap(int i,
                  int j)

sort

public void sort()

compare

public int compare(java.lang.Object a,
                   java.lang.Object b)

Default comparator, does a string comparison on the toString() output of the objects for ordering.

Specified by:
compare in interface Compare