1
1
package com .codefortomorrow .advanced .chapter16 .solutions ;
2
2
3
- // using Lombok for Getters and Setters
4
- import lombok . Setter ;
3
+ // UUID to represent each node's unique ID
4
+ import java . util . UUID ;
5
5
import lombok .AllArgsConstructor ;
6
6
import lombok .Getter ;
7
+ // using Lombok for Getters and Setters
8
+ import lombok .Setter ;
7
9
import lombok .Setter ;
8
- // UUID to represent each node's unique ID
9
- import java .util .UUID ;
10
10
11
11
/**
12
12
* @author ArmeetJatyani
13
13
* March 2021
14
- *
14
+ *
15
15
* Implement a simple LinkedList
16
16
* You will need to create a LinkedListNode class, which represents each item/node in the linked list
17
17
* Required functionality...
25
25
26
26
@ Setter
27
27
public class LinkedList {
28
+
28
29
private LinkedListNode head ;
29
30
30
31
/**
@@ -57,7 +58,7 @@ public LinkedListNode head() {
57
58
*/
58
59
public LinkedListNode tail () {
59
60
LinkedListNode current = head ;
60
- if (current == null ) return null ;
61
+ if (current == null ) return null ;
61
62
62
63
while (current .getNext () != null ) {
63
64
current = current .getNext ();
@@ -107,22 +108,21 @@ public LinkedListNode pop() {
107
108
public String toString () {
108
109
String list = "[" ;
109
110
LinkedListNode current = head ;
110
- if (current == null ) return null ;
111
+ if (current == null ) return null ;
111
112
do {
112
113
list += Integer .toString (current .getValue ()) + ", " ;
113
114
current = current .getNext ();
114
- }
115
- while (current != null );
115
+ } while (current != null );
116
116
117
117
list = list .substring (0 , list .length () - 2 );
118
118
return list + "]" ;
119
119
}
120
-
121
120
}
122
121
123
122
@ Getter
124
123
@ Setter
125
124
class Node {
125
+
126
126
private UUID ID ;
127
127
private int value ;
128
128
@@ -135,10 +135,11 @@ public int value() {
135
135
return this .value ;
136
136
}
137
137
}
138
-
138
+
139
139
@ Getter
140
140
@ Setter
141
141
class LinkedListNode extends Node {
142
+
142
143
private LinkedListNode next ;
143
144
144
145
public LinkedListNode (int value , LinkedListNode next ) {
@@ -150,4 +151,3 @@ public LinkedListNode next() {
150
151
return this .next ;
151
152
}
152
153
}
153
-
0 commit comments