Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stack>
- #include <iostream>
- #include <utility>
- using namespace std;
- class Node
- {
- public:
- Node(int num) : _num(num), _next(NULL){}
- friend class List;
- private:
- int _num;
- Node* _next;
- };
- class List
- {
- public:
- List() : _root(NULL){}
- void add(int rhs)
- {
- if (!_root)
- {
- _root = new Node(rhs);
- }
- else
- {
- Node* tmp = _root;
- while (tmp->_next)
- {
- tmp = tmp->_next;
- }
- tmp->_next = new Node(rhs);
- }
- }
- void print() const
- {
- Node* tmp = _root;
- while (tmp)
- {
- cout << tmp->_num << " ";
- tmp = tmp->_next;
- }
- cout << endl;
- }
- void doubling() // udvoit kazhdoe znachenie
- {
- Node* tmp = _root;
- while (tmp)
- {
- tmp->_num *= 2;
- tmp = tmp->_next;
- }
- }
- ~List()
- {
- Node* tmp = _root;
- while (tmp)
- {
- _root = tmp->_next;
- delete tmp;
- tmp = _root;
- }
- }
- private:
- Node* _root;
- };
- int main()
- {
- List lst;
- lst.add(7);
- lst.doubling();
- lst.add(3);
- lst.doubling();
- lst.print();
- return 0;
- }
Add Comment
Please, Sign In to add comment