我迷路了,真的希望有人能幫助我,我應該創建一個函數,找到重複的數字節點並刪除重複項。每當我運行整個代碼時,我都會陷入0的無限循環中。刪除重複節點
我的主要問題是,我知道我的問題駐留在if (tester.data == current.data)
。我不明白他們爲什麼從不測試或比較(他們的整數)。我很抱歉,如果這是一個模糊的問題,我一直盯着我的屏幕困惑了好幾個小時。
public void removeDuplicate()
{
// removes all duplicate nodes from the list
Node tester = head;
Node previous = head;
Node current = head.next;
while (tester.next != null){
int i = 0;
while(current.next != null){
System.out.println("Stuck here3");
if (tester.data == current.data){
Node tempNode = current.next;
previous.next = tempNode;
current = tempNode;
size--;
System.out.println("Stuck here2");
break;
}
else{
previous = current;
current = current.next;
}
}
System.out.println("Stuck here1");
tester = tester.next;
current = tester.next;
}
}
你能告訴我們你的測試數據嗎?你的代碼乍一看是正確的,因此,它可能是你的數據在那裏有一個循環循環... –
請寫出正確的英文(在需要時使用大寫)。使您的問題更易於閱讀。 – tucuxi
什麼是腦袋?數據的佈局是什麼?否則很難提供幫助...... – tucuxi