From 53781db2757d782c787ce9980b719a21008a995e Mon Sep 17 00:00:00 2001 From: Seymur Date: Sat, 22 Jan 2022 13:19:14 +0400 Subject: [PATCH] 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 --- src/data-structures/linked-list/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/data-structures/linked-list/README.md b/src/data-structures/linked-list/README.md index 656ad68f..f30dbffa 100644 --- a/src/data-structures/linked-list/README.md +++ b/src/data-structures/linked-list/README.md @@ -104,8 +104,9 @@ Remove(head, value) if n.next = tail tail ← n tail.next = null + else + n.next ← n.next.next end if - n.next ← n.next.next return true end if return false