Multiple Stacks - Programmers Heaven

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

lajevardilajevardi Posts: 42Member
Hi guys,
is there anyone can tell me what's the "Multiple Stacks"?! how to build them in c++?
/*i think that we should to use polyMorphysm & virtual methods*/

thanks

Comments

  • IDKIDK Posts: 1,784Member
    : Hi guys,
    : is there anyone can tell me what's the "Multiple Stacks"?! how to build them in c++?
    : /*i think that we should to use polyMorphysm & virtual methods*/
    :
    : thanks
    :
    Have a lot of memmory, then have two pointers. The first is the base pointer i.e the start of the memmory field. The second is the stack pointer. It is that one you use for your funcs.

    It would look something like this:
    [code]
    class stack{
    int*base;
    int*stack;
    int*end;

    stack(){
    /* allocate a lot of memmory with malloc or new, I don't know the
    syntax... Then make stack and base equall the start of the
    memmory and end equall the end of the memmory
    */
    }
    ~stack(){
    /* deallocate the memmory */
    }

    void push(int a){
    *stack = a;
    stack=stack+sizeof(a);
    if(stack>=end){
    //error stack overflow
    }
    }
    int pop(void) {
    int a = *stack;
    stack=stack-sizeof(a);
    if(stack<base){
    //error bad coding
    }
    return a;
    }
    }
    [/code]

    Happy coding wishes
    the one and only
    [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

Sign In or Register to comment.