1 #include <iostream> 2 #include "list1.h" 3 4 using namespace std; 5 6 // statikus membert deklarálni kell!! 7 int list::nid = 0; 8 9 // inicializáló lista 10 // warning-ot ad, mert a mezők deklarációs sorrendje 11 // a list.h-ban mást volt. A list.h az elsődleges! 12 list::list() : id(nid), prev(0), next(0) 13 { 14 ++nid; 15 } 16 17 list::~list() 18 { 19 remove(); 20 } 21 22 list *list::remove() 23 { 24 if ( prev ) prev->next = next; 25 if ( next ) next->prev = prev; 26 next = prev = 0; 27 return this; 28 } 29 30 void list::append( list *lp) 31 { 32 next = lp->next; 33 lp->next = this; 34 prev = lp; 35 if ( next ) next->prev = this; 36 } 37 38 void list::insert( list *lp) 39 { 40 prev = lp->prev; 41 lp->prev = this; 42 next = lp; 43 if ( prev ) prev->next = this; 44 } 45 46 void list::print( ostream& os) const 47 { 48 os << "[ id = " << id << " ]"; 49 } 50 51 ostream& operator<<( ostream& os, const list &l) 52 { 53 l.print(os); 54 return os; 55 } 56 57 58