双链表问题 简单 在线结贴
//构造函数 Node(const T& e1, Node *p = 0, Node *n = 0) { this->info = e1; this->prev = p; //前驱 this->next = n;//后继 }//-----------//尾部添加元素void DoubleList<T>::addToDoubleListTail(const T& e1){ if (isEmpty()) // 如果为空链表 { head = tail = new Node<T>(e1); } else { //① /*Node<T> *ptem; ptem = new Node<T>(e1, tail, 0); tail = tail->next; */ //② /*tail->next = new Node<T>(e1, tail, 0); tail = tail->next;*/ //③ tail = new Node<T>(e1, tail, 0); tail->prev->next = tail; }}tail->prev = tail//前驱指针指向了了自己了。tail->next = 0//把尾部设置为NULL;//建议在纸上画一下就明白了。
[解决办法]
(tail) = new Node<T>(e1, tail, 0);调用构造函数:Node(const T& e1, Node *p = 0, Node *n = 0);
(tail)->info = e1; (tail)->prev = tail; (tail)->next = 0;
[解决办法]
看看这篇文章吧
http://www.cnblogs.com/chenyuming507950417/archive/2011/12/30/2307315.html
[解决办法]