Skip to content

Commit 2d8da5d

Browse files
committed
made all changes 2
1 parent 2b5e02d commit 2d8da5d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public LinkedListNode tail() {
5353
LinkedListNode current = head;
5454
if (current == null) return null;
5555

56-
while (current.getNext() != null) {
56+
while (current.next() != null) {
5757
current = current.next();
5858
}
5959

@@ -68,7 +68,6 @@ public void add(int value) {
6868
if (tail == null) {
6969
head = new LinkedListNode(value, null);
7070
} else {
71-
7271
tail.setNext(new LinkedListNode(value, null));
7372
}
7473
}
@@ -103,7 +102,7 @@ public String toString() {
103102
if (current == null) return null;
104103
do {
105104
list += Integer.toString(current.value()) + ", ";
106-
current = current.getNext();
105+
current = current.next();
107106
} while (current != null);
108107

109108
// Remove trailing comma and space after last list element
@@ -139,4 +138,9 @@ public LinkedListNode(int value, LinkedListNode next) {
139138
public LinkedListNode next() {
140139
return this.next;
141140
}
141+
142+
public void setNext(LinkedListNode next) {
143+
this.next = next;
144+
return;
145+
}
142146
}

0 commit comments

Comments
 (0)