← Back to Pointers
Question 716
Ragged Heap Rows Printed Backwards
Ragged Heap Rows Printed Backwards
Build a ragged (jagged) 2D structure on the heap - an array of row pointers where every row has its own length - print it, then release it. Input (stdin): - Line 1: an integerr, the number of rows (at least 1) - Thenrrows. Each row begins with an integerc, that row's length (at least 1), followed bycintegers. Store the table as anint**: onenew int*[r]array of row pointers, plus onenew int[c]array per row. Keep the row lengths in a heap array as well (new int[r]). Print one line per row with that row's values in REVERSE order, then a total line. For the input: 3 3 1 4 7 1 5 2 2 9 the output is exactly what is shown in Expected Output. Each row line is the literal textRow, the row index,:, then each value preceded by a single space. The final line isTotal:followed by the sum of every value in the whole table. Free the memory you allocate - this question checks for memory leaks. Write everything yourself, includingmain.
Expected Output:
Row 0: 7 4 1 Row 1: 5 Row 2: 9 2 Total: 28
= 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.