修改了707设计链表javascript版本题解的删除节点操作
This commit is contained in:
parent
d89b396aee
commit
99ff6dd216
|
|
@ -847,6 +847,10 @@ MyLinkedList.prototype.deleteAtIndex = function(index) {
|
||||||
if(index < 0 || index >= this._size) return;
|
if(index < 0 || index >= this._size) return;
|
||||||
if(index === 0) {
|
if(index === 0) {
|
||||||
this._head = this._head.next;
|
this._head = this._head.next;
|
||||||
|
// 如果删除的这个节点同时是尾节点,要处理尾节点
|
||||||
|
if(index === this._size - 1){
|
||||||
|
this._tail = this._head
|
||||||
|
}
|
||||||
this._size--;
|
this._size--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue