void selectionSort(int x[], int n) { for (int pass=0; pass<n-1; pass++) { int potentialSmallest = pass; // assume this is smallest //--- Look over remaining elements to find smallest. for (int i=pass+1; i<n; i++) { if (x[i] < x[potentialSmallest]) { //--- Remember index for latter swap. potentialSmallest = i; } } //--- Swap smallest remaining element int temp = x[pass]; x[pass] = x[potentialSmallest]; x[potentialSmallest] = temp; } }