//program Selection Sort #include const int MaxArray = 100; int smallpos(int lo, int hi, int farray[]); //returns position of smallest element between positions lo and hi} void selsort(int fsort[], int lopos, int hipos); // ascending order selection sort of array fsort from lopos to hipos int main() { int sentinel; int i, size; int sort[MaxArray]; cout << "Input a sentinel value (Integer) to terminate input\n"; cin >> sentinel; cout << "\nInput Integers, ending with " << sentinel << " - at most " << MaxArray << endl; i = 0; do { cin >> sort[i]; i++; } while (!(sort[i-1] == sentinel)); size = i - 2; selsort(sort,0,size); for (i = 0; i <= size; i++) { cout << sort[i] << " "; } cout << endl; return 0; } // end main int smallpos(int lo, int hi, int farray[]) //returns position of smallest element between positions lo and hi} { int testpos, small; small = lo; for (testpos = lo; testpos <= hi; testpos++) {if (farray[testpos] < farray[small]) small = testpos; } return small; } // end smallpos void selsort(int fsort[], int lopos, int hipos) // ascending order selection sort of array fsort from lopos to hipos { int pos, sp; int temp; for (pos = lopos; pos < hipos; pos++) { temp = fsort[pos]; sp = smallpos(pos,hipos,fsort); fsort[pos] = fsort[sp]; fsort[sp] = temp; } // end for }