doubleNode *DoubleList::initChain_end() {
auto *head = new doubleNode;
auto prev = head;
cout << "How many?";
int num;
cin >> num;
for (int i = 0; i < num; ++i) {
auto temp = new doubleNode;
temp ->data = i;
prev ->next = temp;
temp ->prior = prev;
prev = temp;
temp ->next = nullptr;//少写则异常输出
}
while(head) head = head ->next;
return head;
}
void DoubleList::display(doubleNode *head) {
auto cur = head -> prior;
while (cur){
cout << cur -> data << " ";
cur = cur -> prior;
}
}
这是一个双链表,为什么第二个函数不能实现逆序输出?(我想从后向前迭代)我在15行已将把head指向最后一个位置了。理论上我每次都把cur指向前一个指针域就行了啊,为什么每次输出都是空?