Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <ctime>
  4. #include <cstdlib>
  5. //#include <stack>
  6. template <typename T>
  7. class stos
  8. {
  9.     private:
  10.         T key;
  11.         stos <T> * next;
  12.     public:
  13.         bool emp() {return this->next==NULL;}
  14.         stos() {this->next=NULL;}
  15.         void pop();
  16.         T top();
  17.         void push(T obj);
  18. };
  19. template <typename T>
  20. void stos<T>::pop()
  21. {
  22.     stos <T> * tmp=this->next;
  23.     this->next=this->next->next;
  24.     delete tmp;
  25. }
  26. template <typename T>
  27. T stos<T>::top()
  28. {
  29.     return this->next->key;
  30. }
  31. template <typename T>
  32. void stos<T>::push(T obj)
  33. {
  34.     stos <T> * tmp=new stos<T>;
  35.     tmp->next=this->next;
  36.     tmp->key=obj;
  37.     this->next=tmp;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement