How to implement three stacks using a single array.

Posted by buried-shopno on Stack Overflow See other posts from Stack Overflow or by buried-shopno
Published on 2010-06-17T08:37:14Z Indexed on 2010/06/17 8:53 UTC
Read the original article Hit count: 304

Filed under:
|

Hi,

I came across this problem in an interview website. The problem asks for efficiently implement three stacks in a single array, such that no stack overflows until there is no space left in the entire array space.

For implementing 2 stacks in an array, it's pretty obvious: 1st stack grows from LEFT to RIGHT, and 2nd stack grows from RIGHT to LEFT; and when the stackTopIndex crosses, it signals an overflow.

Thanks in advance for your insightful answer.

© Stack Overflow or respective owner

Related posts about multiple

Related posts about stack