Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- template <class T> class Stos {
- T *stos;
- unsigned int pos;
- unsigned int stack_size;
- public:
- Stos(unsigned int ssiz){
- stos = (T*)calloc(ssiz, sizeof(T));
- pos = 0;
- stack_size = ssiz;
- };
- void push(T a){
- if(pos+1 > stack_size){ cout << "stack size exceeded" << endl; return; }
- stos[pos] = a;
- pos++;
- }
- T pop(){
- if(pos-1 < 0){ cout << "hit stack bottom" << endl; return NULL; }
- return stos[--pos];
- }
- };
- int main(){
- Stos<string> a(2);
- a.push("Lorem");
- a.push("ipsum");
- cout << a.pop() << endl << a.pop() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement