multiple stacks in an array - Programmers Heaven

Howdy, Stranger!

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

Categories

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.