Ragged Heap Rows Printed Backwards
hardQuestion 716Build 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 integer r, the number of rows (at least 1)
- Then r rows. Each row begins with an integer c, that row's length (at least 1), followed by c integers.
Store the table as an int**: one new int*[r] array of row pointers, plus one new 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 text Row , the row index, :, then each value preceded by a single space. The final line is Total: 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, including main.
Expected output
Row 0: 7 4 1 Row 1: 5 Row 2: 9 2 Total: 28
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...