January 10, 2025 |28.9K Views

    Implement two stacks in an array

      Share  1 Like
    Description
    Discussion

    Create a data structure twoStacks that represents two stacks. Implementation of twoStacks should use only one array, i.e., both stacks should use the same array for storing elements. Following functions must be supported by twoStacks.
    push1(int x) –> pushes x to first stack 
    push2(int x) –> pushes x to second stack
    pop1() –> pops an element from first stack and return the popped element 
    pop2() –> pops an element from second stack and return the popped element
    Implementation of twoStack should be space efficient.

    Implement two stacks in an array: https://www.geeksforgeeks.org/implement-two-stacks-in-an-array/