com.partnersoft.data
Class QuickSort

java.lang.Object
  extended by com.partnersoft.data.QuickSort
All Implemented Interfaces:
SortingAlgorithm

public class QuickSort
extends java.lang.Object
implements SortingAlgorithm

A generic quicksort. Based on chapter 9 of Algorithms, by Robert Sedgewick, 1988 ISBN 0-201-06673-4. Uses pluggable SortingGophers to allow sorting of any list of data.

This isn't declared as a singleton, since it has no actual overhead (no state), so there's not strong reason to limit instantiation. However an standardInstance() method is provided that provides a shared instance.

You can also just use this via the handy convenience method SortingLib.quickSort(SortingGopher); that is actually the recommended method.

Copyright 2000-2006 Partner Software, Inc.

Author:
Paul Reavis

Constructor Summary
QuickSort()
          Creates a new QuickSort algorithm object.
 
Method Summary
 void sort(SortingGopher gopher)
          Sorts using the given SortingGopher.
 void sort(SortingGopher gopher, int start, int end)
          Sorts using the given SortingGopher over the given range (start <= i < end).
static QuickSort standardInstance()
          Returns a singleton shared instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuickSort

public QuickSort()
Creates a new QuickSort algorithm object. Generally you don't need to do this; this constructor is provided to allow serialization and instantiation, but you can almost always just use the standardInstance() method.

Method Detail

standardInstance

public static QuickSort standardInstance()
Returns a singleton shared instance.

Returns:
standard QuickSort instance

sort

public void sort(SortingGopher gopher)
Description copied from interface: SortingAlgorithm
Sorts using the given SortingGopher.

Specified by:
sort in interface SortingAlgorithm
Parameters:
gopher - SortingGopher adapter for underlying array-like structure.

sort

public void sort(SortingGopher gopher,
                 int start,
                 int end)
Description copied from interface: SortingAlgorithm
Sorts using the given SortingGopher over the given range (start <= i < end).

Specified by:
sort in interface SortingAlgorithm
Parameters:
gopher - SortingGopher adapter for underlying array-like structure.
start - starting index (0 is minimum) for sort region (inclusive)
end - ending index for sort region (exclusive)