Guest User

Untitled

a guest
Sep 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. template <class T>
  2. class List {
  3. protected:
  4. struct Node {
  5. T value;
  6. T* next;
  7. Node(T& v = T()) : value(v), next(0) {}
  8. };
  9. Node* head;
  10. Node* tail;
  11. public:
  12. List();
  13. List(const List&);
  14. List& operator =(const List&);
  15. ~List();
  16. void add(const T&);
  17. void remove(Node*);
  18. };
  19. template <class Tp>
  20. class My_stack : public List<Tp> {
  21. public:
  22. void push(const Tp& v) { add(v); }
  23. void pop() { remove(this->tail); }
  24. Tp& top() const { return *(this->tail); }
  25. bool empty() const { return !(this->head) ; }
  26. size_t size() const
  27. {
  28. if (empty()) return 0;
  29. size_t sz{};
  30. for (typename List<Tp>::Node* p = this->head; p; p = p->next)
  31. ++sz;
  32. }
  33. };
Add Comment
Please, Sign In to add comment