Blame | Last modification | View Log | RSS feed
// Written by Ira Snyder
import java.io.*;
class SortMethods {
public static Object[] BubbleSort( Object[] a ) {
for( int i=a.length-1; i>0; i-- )
for( int j=0; j<i; j++ )
if( a[j].compareTo(a[j+1]) ) arraySwap(a,j,j+1);
}
//SelectionSort
//InsertionSort
//ShellSort
//MergeSort
//HeapSort
//QuickSort
public static void arraySwap( Object[] a, int posA, int posB ) {
Object temp = a[posB]; // temp = B
a[posB] = a[posA]; // B = A
a[posA] = temp; // A = temp
}
}