Question: For answering this question, use a CPP/C++ program that prompts the user to enter an integer, the size of your dynamic array first, then enter
For answering this question, use a CPP/C++ program that prompts the user to enter an integer, the size of your dynamic array first, then enter that many numbers to store in the array. Your program will then displays whether the array is sorted or not. If it is not sorted, you will sort it in ascending order and display the sorted array.
Implement the following functions and call them in main.
// Prompts the user to enter a list of sizeOfArray numbers:
i. void getList( int sizeOfArray, int* p);
// returns true if the array is sorted in ascending order, false otherwise
int isSortedAscending(int size, int * ptr);
// returns true if the array is sorted in descending order, false otherwise
ii. int isSortedDescending(int size, int * ptr);
// sort the array
iii. void sortArray(int size, int * p);
// print array
iv. void printArray(int size, int * p);
Here is sample result!
Test running output 1:
Enter the size of the array: 9
Enter the array of 8 numbers: 20 2 5 50 70 9 11 2 3
The array is not sorted !.
The sorted array in ascending order is: 2 2 3 5 9 11 20 50 70
Test running output 2:
Enter the size of the array: 11
Enter the array of 10 numbers: 2 3 3 4 4 6 7 9 20 28 33
The array is already sorted in ascending order.
Test running output 3:
Enter the size of the array: 5
Enter the array of 4 numbers: 50 25 20 16 7
The array is already sorted in descending order
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
