在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);}谢谢。
添加回答
举报
0/150
提交
取消