question
How can you implement 3 Stacks with 1 Array? Optimize for space.
An array has a front, end, and middle. Utilize each of these sections.
1. Start two stacks at opposite ends of the array that grow away from the end points.
2. Start third stack in middle of array growing in either direction
3. The middle stack will eventually collide with one of the end stacks. When this occurs, shift the middle stack away from the collision point to leave equal space on either end.
Thoughts or alternate solution? Let us know in the comments below!
2. Start third stack in middle of array growing in either direction
3. The middle stack will eventually collide with one of the end stacks. When this occurs, shift the middle stack away from the collision point to leave equal space on either end.
Thoughts or alternate solution? Let us know in the comments below!