// Sort ints using the SelectionSort algorithm. public class SelectionSort { public static void main(String[ ] argv) { int[ ] a = { 45, 76, 34, 23, 19, 54, 55 }; for(int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println( ); selectionSort(a); for(int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println( ); } public static void selectionSort(int[ ] a) { int i, j, temp, min, minindex; for(i = 0; i <= a.length - 2; i++) { // Set temporary min to be updated. min = a[i]; minindex = i; // Find min of remaining elements. for(j = i + 1; j <= a.length - 1; j++) if (a[j] < min) { min = a[j]; minindex = j; } // Swap element i with element minindex. temp = a[i]; a[i] = a[minindex]; a[minindex] = temp; } } }