Skip to content

Commit 34aef89

Browse files
committed
Corrected a null pointer exception when linked list has only one element
1 parent 08c9fc8 commit 34aef89

File tree

1 file changed

+3
-1
lines changed
  • lectures/18-linkedlist/code/src/com/kunal

1 file changed

+3
-1
lines changed

Diff for: lectures/18-linkedlist/code/src/com/kunal/CLL.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public void display() {
2828
if (head != null) {
2929
do {
3030
System.out.print(node.val + " -> ");
31-
node = node.next;
31+
if (node.next != null) {
32+
node = node.next;
33+
}
3234
} while (node != head);
3335
}
3436
System.out.println("HEAD");

0 commit comments

Comments
 (0)