//DISPLAY 9.6 A Dynamic Array //Sorts a list of numbers entered at the keyboard. #include #include #include typedef int* IntArrayPtr; void fill_array(int a[], int size); //Precondition: size is the size of the array a. //Postcondition: a[0] through a[size-1] have been //filled with values read from the keyboard. void sort(int a[], int size); //Precondition: size is the size of the array a. //The array elements a[0] through a[size-1] have values. //Postcondition: The values of a[0] through a[size-1] have been rearranged //so that a[0] <= a[1] <= ... <= a[size-1]. int main( ) { using namespace std; cout << "This program sorts numbers from lowest to highest.\n"; int array_size; cout << "How many numbers will be sorted? "; cin >> array_size; IntArrayPtr a; a = new int[array_size]; fill_array(a, array_size); sort(a, array_size); cout << "In sorted order the numbers are:\n"; for (int index = 0; index < array_size; index++) cout << a[index] << " "; cout << endl; delete [] a; return 0; } //Uses the library iostream: void fill_array(int a[], int size) { using namespace std; cout << "Enter " << size << " integers.\n"; for (int index = 0; index < size; index++) cin >> a[index]; } void sort(int a[], int size) //Any implementation of sort may be used. This may or may not require some //additional function definitions. The implementation need not even know that //sort will be called with a dynamic array. For example, you can use the //implementation in Display 7.12 (with suitable adjustments to parameter names).