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

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]

  • lajevardilajevardi Posts: 42Member
    really thanks ;)
Sign In or Register to comment.