Question
Two stacks of positive integers are needed: one containing elements with values less than or equal to 1000 and the other containing elements with values
Two stacks of positive integers are needed: one containing elements with values less than or equal to 1000 and the other containing elements with values larger than 1000. The total number of elements in the small-value stack and the large-value stack combined is never more than 500 at any time, but we cannot predict how many will be in each stack. (Initially both will be empty; later on the stacks could be evenly divided, or all the elements could be in the small-value stack, and so on.) For efficiency reasons, we want to implement both stacks using a single array of size 500. Can you think of a way to do this?
a) Sketch how this double-stack array might look.
b) Describe the private member variables of such a double-stack class, give their initial values, and explain how they are modified by Push/Pop operations. Coding is not required.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started