Simple Sorting(Bubble, Selection & Insertion Sort)
Question: input array: output array: Solution: Bubble Sort: Strategy: Compare two players If the one on the left is taller, swap them Move one position right When you reach the first sorted player, start over at the left end of the line Code: public void bubbleSort() { int out, in; for(out=nElems-1; out>1; out--) { for(in=0; in<out; in++) { if( a[in] > a[in+1] ) { swap(in, in+1); } } } } private void swap(int one, int two) { long temp = a[one]; a[one] = a[two]; a[two] = temp; } Efficiency: O(N 2 ) Selection Sort: Strategy: Making a pass through all the players and picking the shortest one This shortest player is then swapped with the player on the left end of the line, at position 0 The next time pass down the row of players, start at position 1, and, finding the minimum, swap with position 1 This process continues until all the players are sorted Code: public void selectionSort() { in...