Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class Stack{
- int n;
- T* arr;
- int m;
- public:
- Stack(int n = 16){
- this->n = n;
- arr = new T[n];
- m = 0;
- }
- void push(T val){
- if(m == n - 1){
- cout << "Stack overflow" << endl;
- exit(1);
- }
- arr[m] = val;
- m++;
- }
- void pop(){
- if(!isEmpty()){
- m--;
- }else{
- exit(1);
- }
- }
- void top(){
- return arr[m];
- }
- bool isEmpty(){
- return m == 0 ? true : false;
- }
- int size(){
- return m;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement