Skip to content

Commit 53781db

Browse files
Seymurtrekhleb
Seymur
andauthored
Null Reference Exception (trekhleb#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 <[email protected]>
1 parent 4704820 commit 53781db

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/data-structures/linked-list/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ Remove(head, value)
104104
if n.next = tail
105105
tail ← n
106106
tail.next = null
107+
else
108+
n.next ← n.next.next
107109
end if
108-
n.next ← n.next.next
109110
return true
110111
end if
111112
return false

0 commit comments

Comments
 (0)