class List { public: List() : first {nullptr} {} void insert(int v) { first = new Node{v, first}; } int front() const { return first->value; } List(List const& other) : first {copy(other.first)} {} ~List() { while(first != nullptr) { Node* tmp {first}; first = first->next; delete tmp; } } private: struct Node { int value; Node* next; }; Node* first; Node* copy(Node* p) const { if (p == nullptr) { return nullptr; } return new Node{p->value, copy(p->next)}; } };