Class BubbleSort

Sorter
  |
  +--BubbleSort

public class BubbleSort
extends Sorter

Class for performing "instrumented" bubble sort. (See source code at BubbleSort.java.)


Method Summary
 static voidmain(String[] args)
          Performs simple tests.
 static SortResultsort(Comparable[] a)
          Sorts array.
 static SortResultsort(Object[] a, Comparator c)
          Sorts array.
 static voidtestSort(String testName, Object[] a, Comparator c)
          Tests sort: Performs sort, tests result, and prints values of counters, preceded by header message.

Methods inherited from class Sorter
isSorted, printArray, printSearchResult, printSortResult, printSortResult

Method Detail

main

public static void main(String[] args)
Performs simple tests.
Parameters:
args command-line arguments -- data to sort, or none to use default data

sort

public static SortResult sort(Comparable[] a)
Sorts array.
Parameters:
a array to sort (in compareTo orter)
Returns: counters showing number of comparisons and number of swaps

sort

public static SortResult sort(Object[] a, Comparator c)
Sorts array.
Parameters:
a array to sort
c comparator, or null to use array's compareTo method (in which case its elements should be Comparable)
Returns: counters showing number of comparisons and number of swaps

testSort

public static void testSort(String testName, Object[] a, Comparator c)
Tests sort: Performs sort, tests result, and prints values of counters, preceded by header message.
Parameters:
testName "test name" for header message
a array to sort
c comparator, or null to use compareTo