← Back to Pointers
Question 719
Return a Heap Array of Running Maximums
Return a Heap Array of Running Maximums
Write exactly this function: int*runningMax(const int* values, int n);It returns a NEW array ofnints in which elementiis the largest value found invalues[0]throughvalues[i]. The function allocates that array and returns it; it must not print anything. Inmain: read an integern(at least 1), readnintegers into a heap array you allocate withnew int[n], callrunningMax, print the result, and thendelete[]BOTH arrays. Print exactly two lines. For the input5then3 1 7 4 9the output is exactly what is shown in Expected Output. Line 1 is the literal textRunning max:followed by each element of the returned array, each one preceded by a single space. Line 2 isFinal:followed by the last element of that array. Free the memory you allocate - this question checks for memory leaks. Write everything yourself, includingmain.
Expected Output:
Running max: 3 3 7 7 9 Final: 9
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.