Data Abstraction and Structures

One of the stack applications is to backtrack. As example take a list of numbers. Negative numbers, 0, and 1 represent “commends”, the rest of the integers represent “data”. You may assume the input files contain valid data.

o Each time we read 0, display the number of elements in the stack. o Each time we read 1, display the element at the top of the stack. o Each time we read a positive number we push it onto the stack, and o Each time we read a negative number, we pop and print as many values from the stack as the absolute value of the negative number. If there are fewer numbers in the stack, print a message and nothing else. o When the end of the file is detected, print a message and the items left in the stack, if any.

This question has been answered.

Get Answer