[英]Printing All A Linked Lists' Elements (C++)
我正在嘗試使用此函數打印鏈接列表的元素,但是當我這樣做時,它會無限重復列表中的第一項。 任何幫助是appriciated
}
cout << "Your list is: " << endl;
Node * start = head;
while (start)
{
cout << start->data<<endl;
start = head->next;
}
return menu();
}
while (start)
{
cout << start->data<<endl;
start = start->next;
}
會修好。
您的循環在每次迭代時都重新訪問第一個列表項。 您根本沒有進入后續項目。
你需要改變這個
start = head->next;
對此
start = start->next;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.