在C中,這個概念在指針中變得非常清晰,但是我很難理解java中到底發生了什么。有人可以向我解釋一下,當我在demoveNode()中遍歷列表時,它不會改變原始對象上的任何東西,但是當我做front.next = front.next.next時,它實際上會改變對象。它讓我瘋狂,因為在C中,我可以使用指針來編輯w / e我想要的。參考文獻到底是怎么回事?注意:我知道此代碼不處理邊緣情況。如空節點等...public class LLnode{ int value; LLnode next; public LLnode(int x){ this.value = x; this.next = NULL; }}/* * This fn removes the node with the specified value n from the linked list */public void removeNode(LLnode head, int n){ LLnode front = head; while (front.next.value != n){ front = front.next; //why DOESN'T this physically change the LL? } front.next = front.next.next; //why DOES this physically change the LL ?}public static void main(String[] args){ //node creation LLnode a = new LLnode(10); LLnode b = new LLnode(20); LLnode c = new LLnode(30); LLnode d = new LLnode(40); //assignments c.next = d; b.next = c; a.next = b; removeNode(a,30);}謝謝。
為什么此鏈表遍歷有效?參考文獻如何工作?
ibeautiful
2022-09-07 21:12:15