Selection Sort
void selectionSort (apvector<double> &list)
// Uses a temporary variable instead of calling the swap procedure each time
{ int min; int len = list.length( ); for (int j = 0; j < len - 1; j++) { min = j; for ( int k = j + 1; k < len; k++) if (list[min] > list[k]) min = k; swap (list[min], list[j]); } }Insertion Sort
void insertionSort (apvector &list)
// Uses the insertion algorithm that starts at the beginning of the list
{ double saved; int len = list.length( ); int j, k; for (j = 1; j < len; j++) { k = j; saved = list[k]; while (k > 0 && saved < list[k-1] ) { list[k] = list[k-1] k --; } list[k] = saved; } }