Skip to content

Commit e4dffbe

Browse files
committed
added the comments
1 parent c846a5c commit e4dffbe

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Linked-Lists/LinkedListNode.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Linked List Implementation
2+
Linked List Node Implementation
3+
from CtCI
34
45
*/
56

@@ -9,24 +10,24 @@ class LinkedListNode {
910
LinkedListNode prev;
1011

1112
public LinkedListNode() {
12-
1313
}
1414

1515
public LinkedListNode(int d, LinkedListNode n, LinkedListNode p) {
1616
data = d;
1717
this.setNext(n);
1818
this.setPrev(p);
1919
}
20-
20+
//sets the next node
2121
public void setNext(LinkedListNode n) {
2222
next = n;
23-
if(n != null && n.prev != this) {
23+
if(n != null && n.prev != this) { //n.prev is checked in order stop adding the node recursively
2424
n.setPrev(this);
2525
}
2626
}
27+
//sets the prev node
2728
public void setPrev(LinkedListNode p) {
2829
prev = p;
29-
if(p != null && p.next != this) {
30+
if(p != null && p.next != this) { //p.next is to imply termination
3031
this.setNext(p);
3132
}
3233
}

0 commit comments

Comments
 (0)