Question
a. Create a function called resize that can be used to increase the size of integer arrays dynamically. The function takes three parameters. The first
a. Create a function called resize that can be used to increase the size of integer arrays dynamically. The function takes three parameters. The first parameter is the original array, the second parameter is the size of this array, and the third parameter is the size of the larger array to be created by this function. Make sure that you allocate memory from the heap inside this function. After allocating memory for the second array the function must copy the elements from the first array into the larger array. Finally, the function must return a pointer to the new array.
b. In main, allocate an array on the heap that is just large enough to store the integers 5, 7, 3, and 1.
c. Resize the array to store 10 integers by calling the resize function created in step a. Remove the old (smaller) array from the heap. Add the numbers 4, 2, and 8 to the end of the new array.
d. Write a sort function that sorts any integer array in increasing order.
e. Use the sort function to sort the array of numbers in c above. Display the sorted numbers.
Step by Step Solution
3.38 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
include include for sort using namespace std int resizeint int ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started