Skip to content

Instantly share code, notes, and snippets.

@MattiaOng
Created August 2, 2010 11:12
Show Gist options
  • Save MattiaOng/504491 to your computer and use it in GitHub Desktop.
Save MattiaOng/504491 to your computer and use it in GitHub Desktop.
class Stack{
public:
Stack(){
stack^stack;
position=1;
}
void push(bool input){
if(position>32)
puts("Stack overflow");
else{
stack <<= 1;
stack |= input;
position<<=1;
}
}
bool pop(){
if(!(position>>1))
puts("Stack underflow");
else{
position>>=1;
bool pop=stack&position;
stack&(~position);
return pop;
}
}
private:
unsigned stack : 32;
unsigned position : 32;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment