Chapter 3 Stacks and Queues - 3.1Problem 3.1: Describe how you could use a single array to implemen
Chapter 3 Stacks and Queues - 3.1
Problem 3.1: Describe how you could use a single array to implement three stacks.
Splitting the array into three individual parts is quite intuitive.
How can we take full advantage of the unused space? I was inspired by the implementation of circular queue. Actually, in my perspective, my solution is better than the one on answer page. The idea is not complicated: When there is no free space next to top of the stack, into which we want to push a value, I shift other stacks to make a free space available for the stack.
It takes me more than two hours to implement the class. Thanks to work break down method, I encapsulated some work into utility functions and made the implementation quite smooth.
