#include <stdio.h> #include <iostream.h> class CNode { private: int item; CNode *next; public: CNode(int item = 0, CNode *next = NULL) { this->item = item; this->next = next; } ~CNode(){} friend class CList; }; class CList { private: CNode *head; public: CList(); ~CList(); CList(const CList &L); CList &operator =(const CList &L); void Show(); void Insert(int item); }; CList::CList() { head = new CNode; } CList::~CList() { while(head->next){ CNode *t = head->next; delete head; head = t; } delete head; } CList::CList(const CList &L) { head = new CNode; CNode *t1, *t2; t2 = head; for(t1 = L.head->next; t1; t1 = t1->next){ t2->next = new CNode(t1->item, t1->next); t2 = t2->next; } } CList& CList::operator =(const CList &L) { while(head->next){ CNode *t = head->next; delete head; head = t; } CNode *t1, *t2; t2 = head; for(t1 = L.head->next; t1; t1 = t1->next){ t2->next = new CNode(t1->item, t1->next); t2 = t2->next; } return *this; } void CList::Show() { for(CNode *t = head->next; t; t = t->next){ cout << t->item << " "; } cout << endl; } void CList::Insert(int item) { CNode *t; for(t = head; t->next; t = t->next){ if(t->next->item <= item) break; } t->next = new CNode(item, t->next); } int main(void) { CList L1; for(int i = 0; i < 10; i++) L1.Insert(i); L1.Show(); CList L2(L1); L2.Show(); CList L3; L3 = L2; L3.Show(); return 0; }