下面是爲了顛倒鏈表。它似乎工作,直到它到達最後一行。當我調試時,「當前」和「結果」是相同的類型(節點*)和「結果」是顛倒的列表。但是當函數完成時,當前只有「結果」列表的第一個值。任何人都知道爲什麼「當前」不是函數完成時的完整列表?指針有點麻煩
struct Node {
int data;
Node* next;
};
void reverseList(Node** head)
{
Node* current = *head;
Node* result = NULL;
while (current != NULL)
{
Node* temp = current;
current = temp->next;
temp->next = result;
result = temp;
}
current = result;
}
什麼是「原創」? – Chris