【发布时间】:2017-04-30 15:37:42
【问题描述】:
没有找到这个问题的简化版本。
我是 listnodes 的新手,所以我可能只是不太了解它们。在我通过我的 for 循环之前,一切似乎都可以正常工作。
while(temp2 != NULL){
for(int i = temp2->data; i > 0; i--){
//////////////
temp1 = head;
temp3 = Product.head;
while(temp1 != NULL || temp3 != NULL){
cout << "\ntemp1->data: " << temp1->data;
cout << "\ntemp3->data: " << temp3->data;
temp1 = temp1->next;
temp3 = temp3->next;
}
/////////////
cout << "\n\ndecrement: " << i;
}
temp2 = temp2->next;
}
除了在 cmets 之间之外,一切都运行。
我的想法是我可以遍历到 listnode (temp1) 的末尾,然后一旦我到达末尾,我就指向头部并根据需要多次遍历它。不过我遇到了分段错误。
我不能很好地遍历 temp2,但是当多次遍历 temp1 时我做错了什么?我可以只引用一次列表的头部吗?
编辑:我发现我刚刚留下了一个条件。现在它是我的第三个列表,它给了我分段错误。它将运行一个循环,但一旦退出 while 循环,它就会中断。
【问题讨论】:
-
||条件应该是 &&。
标签: c++ linked-list