标签:
链表结点类模板定义:
1 template <class T> 2 class SingleList; 3 template <class T> 4 class Node 5 { 6 private: 7 T element; 8 Node<T> *link; 9 friend class SingleList<T>; 10 };
链表类末班定义:
1 template <class T> 2 class SingleList 3 { 4 public: 5 SingleList() 6 { 7 first = NULL; 8 n = 0; 9 } 10 ~SingleList(); 11 void Upstream(); 12 private: 13 Node<T>* first; 14 };
链表逆置成员函数:
1 template<class T> 2 void SingleList<T>::Upstream() 3 { 4 Node<T> *p = first; 5 Node<T> *curr = p->link; 6 Node<T> *tmp = NULL; 7 8 p->link = NULL; 9 while (curr) 10 { 11 tmp = curr->link; 12 curr->link = p; 13 p = curr; 14 curr = tmp; 15 16 } 17 18 first->link = NULL; 19 first = p; 20 }
标签:
原文地址:http://www.cnblogs.com/zlgxzswjy/p/4804918.html