UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.util
Class Sort

java.lang.Object
  |
  +--edu.berkeley.guir.lib.util.Sort

public class Sort
extends Object

Various sorting algorithms.

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.0-1.0.0, Mar 29 1997, KT
               Created class
             - GUIRLib-v1.0-1.0.1, Nov 29 1997, JH
               Added bidirectional bubble sort
               Modified to allow sorting of Objects
             - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib release
 

Since:
JDK 1.1.4
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu), Khai Truong ( khai@cc.gatech.edu)

Constructor Summary
Sort()
           
 
Method Summary
static long bidirBubbleSort(int[] theArray)
          Performs a bidirectional "bubble" sort on theArray passed in.
static long bidirBubbleSort(Object[] theArray, Comparison compare)
          Performs a bidirectional "bubble" sort on theArray passed in.
static long bubbleSort(int[] theArray)
          Performs a "bubble" sort on theArray passed in.
static long bubbleSort(Object[] theArray, Comparison compare)
          Performs a "bubble" sort on theArray passed in.
static long heapSort(int[] theArray)
          Performs a "heap" sort on theArray passed in.
static long heapSort(Object[] theArray, Comparison compare)
          Performs a "heap" sort on theArray passed in.
static long insertionSort(int[] theArray)
          Performs an "insertion" sort on theArray passed in.
static long insertionSort(Object[] theArray, Comparison compare)
          Performs an "insertion" sort on theArray passed in.
static void main(String[] argv)
          Performs a "tree" sort on theArray passed in.
static long mergeSort(int[] theArray)
          Performs a "merge" sort on theArray passed in.
static long mergeSort(Object[] theArray, Comparison compare)
          Performs a "merge" sort on theArray passed in.
static long quickSort(int[] theArray)
          Performs a "quick" sort on theArray passed in.
static long quickSort(Object[] theArray, Comparison compare)
          Performs a "quick" sort on theArray passed in.
static long selectionSort(int[] theArray)
          Performs a "selection" sort on theArray passed in.
static long selectionSort(Object[] theArray, Comparison compare)
          Performs a "selection" sort on theArray passed in.
static long shellSort(int[] theArray)
          Performs a "shell" sort on theArray passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sort

public Sort()
Method Detail

bubbleSort

public static final long bubbleSort(int[] theArray)
Performs a "bubble" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
Returns:
Returns the time in milliseconds used to perform the sort.

bubbleSort

public static final long bubbleSort(Object[] theArray,
                                    Comparison compare)
Performs a "bubble" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
compare - is a Comparison that allows Objects to be compared.
Returns:
Returns the time in milliseconds used to perform the sort.
See Also:
Comparison

bidirBubbleSort

public static final long bidirBubbleSort(int[] theArray)
Performs a bidirectional "bubble" sort on theArray passed in. Based on the JDK demo code (by Gosling).
Parameters:
theArray - is the array of ints to be sorted.
Returns:
Returns the time in milliseconds used to perform the sort.

bidirBubbleSort

public static final long bidirBubbleSort(Object[] theArray,
                                         Comparison compare)
Performs a bidirectional "bubble" sort on theArray passed in. Based on the JDK demo code (by Gosling).
Parameters:
theArray - is the array of ints to be sorted.
compare - is a Comparison that allows Objects to be compared.
Returns:
Returns the time in milliseconds used to perform the sort.

heapSort

public static final long heapSort(int[] theArray)
Performs a "heap" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
Returns:
Returns the time in milliseconds used to perform the sort.

heapSort

public static final long heapSort(Object[] theArray,
                                  Comparison compare)
Performs a "heap" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
compare - is a Comparison that allows Objects to be compared.
Returns:
Returns the time in milliseconds used to perform the sort.

insertionSort

public static final long insertionSort(int[] theArray)
Performs an "insertion" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
Returns:
Returns the time in milliseconds used to perform the sort.

insertionSort

public static final long insertionSort(Object[] theArray,
                                       Comparison compare)
Performs an "insertion" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
compare - is a Comparison that allows Objects to be compared.
Returns:
Returns the time in milliseconds used to perform the sort.

mergeSort

public static final long mergeSort(int[] theArray)
Performs a "merge" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
Returns:
Returns the time in milliseconds used to perform the sort.

mergeSort

public static final long mergeSort(Object[] theArray,
                                   Comparison compare)
Performs a "merge" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
compare - is a Comparison that allows Objects to be compared.
Returns:
Returns the time in milliseconds used to perform the sort.

quickSort

public static final long quickSort(int[] theArray)
Performs a "quick" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
Returns:
Returns the time in milliseconds used to perform the sort.

quickSort

public static final long quickSort(Object[] theArray,
                                   Comparison compare)
Performs a "quick" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
compare - is a Comparison that allows Objects to be compared.
Returns:
Returns the time in milliseconds used to perform the sort.

selectionSort

public static final long selectionSort(int[] theArray)
Performs a "selection" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
Returns:
Returns the time in milliseconds used to perform the sort.

selectionSort

public static final long selectionSort(Object[] theArray,
                                       Comparison compare)
Performs a "selection" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
compare - is a Comparison that allows Objects to be compared.
Returns:
Returns the time in milliseconds used to perform the sort.

shellSort

public static final long shellSort(int[] theArray)
Performs a "shell" sort on theArray passed in. Not implemented yet.
Parameters:
theArray - is the array of ints to be sorted.
Returns:
Returns the time in milliseconds used to perform the sort.

main

public static void main(String[] argv)
Performs a "tree" sort on theArray passed in.
Parameters:
theArray - is the array of ints to be sorted.
Returns:
Returns the time in milliseconds used to perform the sort.

Copyright Information