Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- class List {
- protected:
- struct Node {
- T value;
- T* next;
- Node(T& v = T()) : value(v), next(0) {}
- };
- Node* head;
- Node* tail;
- public:
- List();
- List(const List&);
- List& operator =(const List&);
- ~List();
- void add(const T&);
- void remove(Node*);
- };
- template <class Tp>
- class My_stack : public List<Tp> {
- public:
- void push(const Tp& v) { add(v); }
- void pop() { remove(this->tail); }
- Tp& top() const { return *(this->tail); }
- bool empty() const { return !(this->head) ; }
- size_t size() const
- {
- if (empty()) return 0;
- size_t sz{};
- for (typename List<Tp>::Node* p = this->head; p; p = p->next)
- ++sz;
- }
- };
Add Comment
Please, Sign In to add comment