
Effi ciency of Algorithms 385
minsortdouble array[], int N)
{
this.array = array;
this.N = N;
for(int i=0; i < N; i++){
swap(i, findMin(i));
}
}
// findMin(M) finds the index of the minimum among
// array[M], array[M+1], ...., array[N – 1].
int findMin(int sortFrom){
// by default, the element at minSoFar is the minimum
int minSoFar = sortFrom;
for(int j = sortFrom+1; j < N; j++){
if(array[j] < array[minSoFar]){
minSoFar = j; // a smaller value is found
}
}
return minSoFar;
}
// swap(i,j) interchanges the values in array[i] and array[j]
void swap(int i, int j){
double temp = array[i];
array[i] ...