Created
August 2, 2010 11:12
-
-
Save MattiaOng/504491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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