Here is some pseudo-code for Selection Sort. My version keeps the right portion of the array sorted and inserts items a[n-2] down to a[0] The version most commonly seen keeps the right portion of the array sorted and inserts items a[2] through a[n-1] InsertionSort: /* a[0] to a[n-1] is the array to sort */ // items a[i+1] through a[n-1] are assumed to be sorted. // inserting item a[i] in it's correct place for ( i = n-2; i >= 0; i-- ) { // save item to be inserted save = a[i]; j = i+1; // going from left to right, move items over if they are less than save while( j < n && a[j] < save ) { a[j-1] = a[j]; j++; } // put save in its correct location a[j-1] = save; } This version from Wikipedia is close to what I presented in class: /* a[0] to a[n-1] is the array to sort */ int iPos; int iMin; /* advance the position through the entire array */ /* (could do iPos < n-1 because single element is also min element) */ for (iPos = 0; iPos < n; iPos++) { /* find the min element in the unsorted a[iPos .. n-1] */ /* assume the min is the first element */ iMin = iPos; /* test against all other elements */ for (i = iPos+1; i < n; i++) { /* if this element is less, then it is the new minimum */ if (a[i] < a[iMin]) { /* found new minimum; remember its index */ iMin = i; } } /* iMin is the index of the minimum element. Swap it with the current position */ if ( iMin != iPos ) { swap(a, iPos, iMin); } }