class Cell{ int info; Cell *next; Cell(int i){ info = i; next = this; } Cell(int i, Cell *n){ info = i; next = n; } friend class List; }; class List{ Cell *rear; public: void push(int i){ rear->next = new Cell(i,rear->next); } int pop(){ if (empty()) return 0; Cell *front = rear->next; rear->next = front->next; int i = front->info; delete front; return i; } bool empty(){ return rear == rear->next; } List() { rear = new Cell(0); } ~List() { while (!empty()) pop(); delete rear; } }; #include List *listall(int n){ List *l = new List(); while (n>0) l->push(n--); return l; } void printall(List *l){ while (!(l->empty())) cout << l->pop() << '\n'; } main(){ List *l = new List(); l->push(1); l->push(2); List *k = l; delete k; }