In our first case study on evaluating arithmetic expressions, we used two stacks that held different types
Question:
In our first case study on evaluating arithmetic expressions, we used two stacks that held different types of data. In some other applications, we might need two stacks with the same type of data. If we implement the stacks as arrays, there is a chance that one array (and hence one stack) will become filled, causing our computation to end prematurely. This might be a shame since the other array (stack) might have plenty of room. One way around this problem is to implement two stacks as one large array rather than two smaller arrays. Write a class for a pair of stacks. A pair of stacks is simply an object with two stacks. Call these stacks StackA and StackB. There should be separate operations for each stack, for example, pop_a and pop_b. Implement the stack pair as a single array. The two stacks grow from the two ends of the array, so for example, one stack could fill up one quarter of the array while the other fills up three quarters.
Use int for the underlying type of the stack data.
Step by Step Answer: