java链表的疑惑

head.next = tail;  tail = new ListNode(); 为什么head.next不等于tail

在cpp里面

head->next = tail;

tail = new ListNode();

这时head->next == tail.这是因为head->next存放的是tail的地址,

而java中head.next = tail;  tail = new ListNode(); head.next存放的是tail的之前值,之后tail的值改变了,head.next的值不会随之改变。所以head.next != tail 。

posted @ 2023-05-08 12:05  My_Z  阅读(15)  评论(0)    收藏  举报