GeeksforGeeks » Algorithms
Implementing 2 stacks within a single linear array
(7 posts)-
Hi all,
Can someone suggest me an efficient way to implement 2 stacks within a single linear array assuming that neither stack overflows and the entire stack can be shifted elsewhere in the array. Both the stacks should have their respective push and pop functions. -
Use both ends to represent the two stacks.
-
How to implement 3 stacks using the same?
-
Let the array size be n.
Maintain 3 variables s1, s2 and s3 for maintaining starting points of 3 stacks.
s1 = 0
s2 = n/3
s3 = 2n/3If any of the stack overflows then move elements and change starting points of 3 stacks
-
@kapil, can you please explain it little more?
-
please visit the bellowed link,
Reply
You must log in to post.