arlut.csd.Util
Class VecQuickSort

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

public class VecQuickSort
extends java.lang.Object
implements Compare

QuickSort implementation for Vector. Uses the Compare interface for item comparisons.

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.util.Vector objects
           
 
Constructor Summary
VecQuickSort(java.util.Vector objects, Compare comparator)
          VecQuickSort constructor.
 
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()
          Sort the elements
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.util.Vector objects

comparator

Compare comparator
Constructor Detail

VecQuickSort

public VecQuickSort(java.util.Vector objects,
                    Compare comparator)
VecQuickSort constructor.
Parameters:
objects - Vector of objects to be sorted in place
comparator - Compare object.. if null, standard string compare will be done.
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()

Sort the elements


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