mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-09 04:08:42 +08:00
Null Reference Exception (#817)
When `n.next = tail` is true, we assign `n` to `tail` and `null` to `tail.next`, so `n.next` also becomes `null`. Then we assign `n.next.next` (because now `n.next` is `null`), we try to get `next` of `null`. That is why we should add an `else` case to check if `n.next` is not equal to `tail`. Co-authored-by: Oleksii Trekhleb <trehleb@gmail.com>
This commit is contained in:
@ -104,8 +104,9 @@ Remove(head, value)
|
|||||||
if n.next = tail
|
if n.next = tail
|
||||||
tail ← n
|
tail ← n
|
||||||
tail.next = null
|
tail.next = null
|
||||||
|
else
|
||||||
|
n.next ← n.next.next
|
||||||
end if
|
end if
|
||||||
n.next ← n.next.next
|
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
return false
|
return false
|
||||||
|
Reference in New Issue
Block a user