public class SortingTools { public static void SelectionSort(BankAccount[] a) { BankAccount help; // helper variable for 3-way exchange int i, j, min_j; // Array indices /* --------------------------------------------------- The selection sort algorithm --------------------------------------------------- */ for ( i = 0 ; i < a.length ; i ++ ) { /* --------------------------------------------------- Find array element with min. value among a[i], a[i+1], ..., a[n-1] --------------------------------------------------- */ min_j = i; // Assume elem i (a[i]) is the minimum for ( j = i+1 ; j < a.length ; j++ ) { if ( a[j].getBalance() < a[min_j].getBalance() ) { min_j = j; // We found a smaller minimum, update min_j } } /* --------------------------------------------------- Swap a[i] and a[min_j] --------------------------------------------------- */ help = a[i]; a[i] = a[min_j]; a[min_j] = help; } } }