1 template 2 class List 3 { 4 private: 5 struct Node//所有都是公有的 6 { 7 Object data; 8 Node *prev; 9 Node *next; 10 11 Node(const Object & d = Object(),Node *p = NUll,Node *n = Null): 12 data(d) , prev(p) , next(n) 13 { 14 } 15 }; 16 public: 17 class const_iterator 18 { 19 public: 20 const_iterator() : current(NULL){} 21 const Object & operator* () const 22 { 23 return retrieve(); 24 } 25 const_iterator & operator++ ( ) const 26 { 27 current = current->next; 28 return *this; 29 } 30 const_iterator & operator++( int ) 31 { 32 const_iterator old = *this; 33 ++(*this); 34 return old; 35 } 36 bool operator == (const const_iterator * rhs) const 37 { 38 return current == rhs.current; 39 } 40 bool operator != (const const_iterator & rhs) const 41 { 42 return !(*this == rhs); 43 } 44 45 protected: 46 Node *current; 47 48 Object & retrieve() cosnt 49 { 50 return current->data; 51 } 52 const_iterator(Node *p) : current(p) 53 { 54 } 55 friend class List