arrange-an-array-of-integers-in-ascending-order-computer-science-homework-help
/ This program uses a selection sort to arrange an array of integers in
// ascending order_x000D_ _x000D_ //PLACE YOUR NAME HERE_x000D_ #include <iostream>_x000D_ using namespace std;_x000D_ // function prototypes_x000D_ void selectionSortArray(int [], int);_x000D_ void displayArray(int[], int);_x000D_ const int SIZE = 5;_x000D_ int main()_x000D_ {_x000D_ int values[SIZE] = {9,2,0,11,5};_x000D_ cout << "The values before the selection sort is performed are:" << endl;_x000D_ displayArray(values,SIZE);_x000D_ selectionSortArray(values,SIZE);_x000D_ cout << "The values after the selection sort is performed are:" << endl;_x000D_ displayArray(values,SIZE);_x000D_ return 0;_x000D_ }_x000D_ _x000D_ //******************************************************************_x000D_ //displayArray_x000D_ //_x000D_ // task:to print the array_x000D_ // data in:the array to be printed, the array size_x000D_ // data out:none_x000D_ //_x000D_ //******************************************************************_x000D_ void displayArray(int array[], int elems)// function heading_x000D_ {// Displays array for (int count = 0; count < elems; count++)_x000D_ cout << array[count] << "";_x000D_ cout << endl;_x000D_ }_x000D_ _x000D_ //******************************************************************_x000D_ //selectionSortArray_x000D_ //_x000D_ // task:to sort values of an array in ascending order_x000D_ // data in:the array, the array size_x000D_ // data out:the sorted array_x000D_ //_x000D_ //******************************************************************_x000D_ void selectionSortArray(int array[], int elems)_x000D_ {_x000D_ int seek;// array position currently being put in order int minCount;// location of smallest value found_x000D_ int minValue;// holds the smallest value found_x000D_ for (seek = 0; seek < (elems-1);seek++)// outer loop performs the swap_x000D_ // and then increments seek_x000D_ {_x000D_ minCount = seek;_x000D_ minValue = array[seek];_x000D_ for(int index = seek + 1; index < elems; index++)_x000D_ {_x000D_ // inner loop searches through array_x000D_ // starting at array[seek] searching_x000D_ // for the smallest value. When the_x000D_ // value is found, the subscript is_x000D_ // stored in minCount. The value is_x000D_ // stored in minValue._x000D_ if(array[index] < minValue)_x000D_ {_x000D_ minValue = array[index];_x000D_ minCount = index;_x000D_ }_x000D_ }_x000D_ _x000D_ // the following two statements exchange the value of the_x000D_ // element currently needing the smallest value found in the_x000D_ // pass(indicated by seek) with the smallest value found_x000D_ // (located in minValue)_x000D_ array[minCount] = array[seek];_x000D_ array[seek] = minValue;_x000D_ _x000D_ }_x000D_ }_x000D_ _x000D_ Exercise 1: Re-write the sort program you chose so that it orders integers from largest to smallest rather than smallest to largest._x000D_ Exercise 2: Modify your program from Exercise 1 so that it prints the array at each step of the algorithm.