【发布时间】:2018-11-11 14:34:15
【问题描述】:
我最近在 youtube 上观看了一系列 LinkedList 视频,如下图所示:
视频网址:https://www.youtube.com/watch?v=2RwWsHePdr8&index=11&list=PL6Zs6LgrJj3tWQfE6HK4JaX3wN96yhkD3
不,我想删除数字 15(位置 3),所以这里是代码:
if(position ==1) {
ListNode temp = head;
head = head.next;
temp.next = null;
return temp;
}else {
ListNode previous = head;
int count =1;
while(count < position -1) {
previous = previous.next;
count++;
}
ListNode current = previous.next;
previous.next = current.next;
current.next = null;
return current;
}
我有一个问题让我很困惑:图片中:|10|_|--> | 8 | __ | 如果我输入:『head.next』,意思是 8 吗?还是指10旁边的节点空间?
因为在我透露的代码中,我无法理解:“为什么最后一个代码是『current.next = null;』?” 我认为『current.next』指向11号?? 如果『current.next』表示15的下一个节点,那么之前的代码『previous.next = current.next』是否应该改为『previous.next = current.next.next』?也就是说『current.next.next』可以参考11号
提前致谢!!
更新:head.next 和 head.next.next 是这样的意思吗? enter image description here
【问题讨论】: