Insertion Sort In Java

public class Test {	final static boolean DEBUG = false; /*	public static void main(String [] args) {		int array [] = {12,56,34,99,11,22,66,33,92,1}; double array2 [] = {12.,56.,34.,99.,11.,22.,66.,33.,92.,1.}; printArray(array2); insertionSort(array2); printArray(array2); } //must rewrite for each other primitive type you need to sort public static void insertionSort( int [ ] a ) {		int testIndex;

for( int nextToInsertINDEX = 1; nextToInsertINDEX < a.length; nextToInsertINDEX++ ) {			int nextToInsertVALUE = a[nextToInsertINDEX]; for(testIndex = nextToInsertINDEX; ((testIndex > 0) && (nextToInsertVALUE < a[testIndex - 1])); testIndex-- ) a[testIndex] = a[testIndex - 1];	//move element up one spot a[testIndex] = nextToInsertVALUE;	//place element in proper position in sorted subarray if (DEBUG) printArray(a); }	}	public static void printArray (int a []) {		System.out.print("{"); for(int i = 0; i < a.length-1; i++) System.out.print(a[i] + ", "); System.out.println(a[a.length-1] + "}"); }

public static void main(String [] args) {		Comparable array [] = {12,56,34,99,11,22,66,33,92,1}; Comparable array2 [] = {12.,56.,34.,99.,11.,22.,66.,33.,92.,1.}; printArray(array); insertionSort(array); printArray(array); printArray(array2); insertionSort(array2); printArray(array2); }

//Works for all Comparable types public static void insertionSort( Comparable [ ] a ) {		int testIndex;

for( int nextToInsertINDEX = 1; nextToInsertINDEX < a.length; nextToInsertINDEX++ ) {			Comparable nextToInsertVALUE = a[nextToInsertINDEX]; for(testIndex = nextToInsertINDEX; ((testIndex > 0) && (nextToInsertVALUE.compareTo(a[testIndex - 1]) < 0)); testIndex--) a[testIndex] = a[testIndex - 1]; a[testIndex] = nextToInsertVALUE; if (DEBUG) printArray(a); }	}

public static void printArray (Comparable a []) {		System.out.print("{"); for(int i = 0; i < a.length-1; i++) System.out.print(a[i] + ", "); System.out.println(a[a.length-1] + "}"); } }