Two stacks of positive integers are needed, one containing elements with values less than or equal to

Question:

Two stacks of positive integers are needed, one containing elements with values less than or equal to 1,000 and the other containing elements with values larger than 1,000. The total number of elements in the small-value stack and the large-value stack combined is not more than 200 at any time, but we cannot predict how many are in each stack. (All of the elements could be in the small-value stack, they could be evenly divided, both stacks could be empty, and so on.) Can you think of a way to implement both stacks in one array?

1. Draw a diagram of how the stack might look.
2. Write the definitions for such a double-stack structure.
3. Implement the Push operation; it should store the new item into the correct stack according to its value (compared to 1,000).

Step by Step Answer:

Related Book For  book-img-for-question

C++ Plus Data Structures

ISBN: 9781284089189

6th Edition

Authors: Nell Dale, Chip Weems, Tim Richards

Question Posted: