/////////////////////////////////////////////////////////////////////////////// // // SelectionSort.cpp // Input: list length n, and array list. // Output: list in increasing order. // /////////////////////////////////////////////////////////////////////////////// #include using namespace std; #define MAX_LIST_LEN 100 int main(){ int n, // list length j, // loop control i, // index of maximum element in unsorted section R; // index of rightmost element in unsorted section double max, // maximum value in unsorted section temp, // temporary storage list[MAX_LIST_LEN]; // array to be sorted // Get values for n and list. cout << "Enter list length (must be less than or equal to " << MAX_LIST_LEN << "): "; cin >> n; cout << "Enter " << n << " numbers:" << endl; for(j=0; j> list[j]; } // perform SelectionSort algorithm on list for(R=n-1; R>0; R--){ // find index i of maximum element in unsorted section max = list[0]; i = 0; for(j=1; j<=R; j++){ if( list[j] > max ){ max = list[j]; i = j; } } // swap list[i] with list[R]. temp = list[i]; list[i] = list[R]; list[R] = temp; } // Print out sorted list. for(j=0; j