我在打印一個單獨鏈表時遇到了問題,它必須查找例如: [1:2] [3:4] [7:2] [9:1 ],但結果/輸出沒有最後一個元素,即:[1:2] [3:4] [7:2]。這是我的數據結構:在C++中打印一個簡單的鏈表,數據結構
struct numbers {
int info1;
int info2;
numbers *next;
};
struct numbers* next= NULL; //At first 0,because the list is empty
struct numbers* head=NULL; //at the beginning
和作用,我後來打電話:
void printing(numbers *head) {
numbers *temp=head;
if(head!=NULL) {
do {
printf("[%d:%d]",temp->info1, temp->info2);
temp=temp->next;
} while(temp->next!=head && temp->next!=0);
}
return;
}
有沒有搞錯在這個功能呢?
'頭= NULL'應該是'TEMP = NULL' – NendoTaka
同時;!(TEMP =頭&& TEMP = 0!) – Tim3880
temp-> next!= 0應該是temp!= NULL –