#include <iostream>
#include <memory>

using namespace std;


class List {
    struct Node;
    using PNode = std::shared_ptr<Node>;
    using PWNode = std::weak_ptr<Node>;
    struct Node : public std::enable_shared_from_this<Node> {

        Node(int v) : value_(v) { cout << "C-tor " << value_ << endl; }

        PNode getptr() {
            return shared_from_this();
        }

        ~Node() { cout << "D-tor " << value_ << endl; }
        int value_;

        PNode next_; //element nastepny
        PNode next_eq_; //element o tej samej wartosci
    };

public:
    List() {}
    ~List() {}

    void push_front(int value) {
        PNode node = make_shared<Node>(value);
        node->next_ = head_;
        head_ = node;

        for(PNode n = head_->next_; n != nullptr; n = n->next_) {
            if(n->value_ == value) {
                node->next_eq_ = n;
                break;
            }
        }
    }
    void debug() {
        PNode x = head_;
        do {
            if(x) {
                cout << x->value_ << ", ";
                x = x->next_;
            }
        } while (x && x != head_);
        cout << endl;
    }
private:
    PNode head_;
};


int main() {
    {
        List l1;
        l1.debug();
        l1.push_front(1);
        l1.push_front(1);
        l1.push_front(1);
        l1.push_front(1);
        l1.debug();
    }
    return 0;
}
