Displaying Free Array Elements
Extend the info function to also display the unused/available array elements. After displaying the elements on the stack, print a vertical bar followed by the available array elements.
For example, the operations push(3), push(4), and then pop() should result in the following output:
1 2 3 4 5 6 7 | MCL:tmp lehn$ ./a.out top = 3 stack: [3] | [0] [0] [0] [0] top = 4 stack: [3] [4] | [0] [0] [0] top = 3 stack: [3] | [4] [0] [0] [0] |
This output clearly demonstrates that during a pop operation, an array element is not “deleted” or overwritten; only the stack pointer is decremented.
Keep the following in mind: In the program, stack is defined as an array with a dimension of 5. If this dimension is changed (for example, to 10), it should not be necessary to modify the info function. The info function should automatically adapt to the new dimension of the stack array and remain functional.