sort2.cc From Astrachan, p 531 ------------------------------ void Sort(Vector & a, int numElts) // precondition: a contains numElts ints // postcondition: elements of a are sorted in non-decreasing order { int j,k,temp,minIndex; for(k=0; k < numElts - 1; k++) { minIndex = k; // smallest item from k to end of a for(j=k+1; j < numElts; j++) { if (a[j] < a[minIndex]) { minIndex = j; // new smallest item, remember where } } temp = a[k]; // swap smallest item and k-th item a[k] = a[minIndex]; a[minIndex] = temp; } }