GeeksforGeeks » Algorithms

Implementing 2 stacks within a single linear array

(7 posts)

Tags:

  1. Raj
    guest
    Posted 1 year ago #

    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.

  2. amarkrdubedy
    Member
    Posted 1 year ago #

    Use both ends to represent the two stacks.

  3. raj
    Member
    Posted 1 year ago #

    How to implement 3 stacks using the same?

  4. kapil
    guest
    Posted 1 year ago #

    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/3

    If any of the stack overflows then move elements and change starting points of 3 stacks

  5. geek4u
    guest
    Posted 1 year ago #

    @kapil, can you please explain it little more?

  6. syclopse
    guest
    Posted 10 months ago #

    please visit the bellowed link,

    http://wiki.answers.com/Q/Two_stacks_in_one_array

  7. as
    guest
    Posted 6 months ago #


Reply

You must log in to post.

RSS feed for this topic