Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

multiple stacks in an array

anish444anish444 Posts: 18Member
hey guys cn anyone tell me how to write a c++ program to store 2 stacks in a single array & then perform operations like push and pop on it??

Comments

  • tom_swtom_sw Posts: 828Member
    : hey guys cn anyone tell me how to write a c++ program to store 2 stacks in a single array & then perform operations like push and pop on it??
    :
    Create a class to represent the stack object, then create an array of stack objects:
    [code]
    class MyStack
    {
    public:
    MyStack();
    Push(int a);
    int Pop();
    ...
    private:
    int* stack_head;
    int stack_count;
    }

    // in main:

    MyStack stacks[2];

    stacks[0].Push(1);
    stacks[1].Push[2];

    stacks[0].Pop();
    stacks[1].Pop();
    [/code]
Sign In or Register to comment.