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*/
: 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]
Comments
: 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]