You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//For better O.O design this should be private allows for better black box design
11
12
privateintsize;
12
13
//this will point to dummy node;
13
14
privateNode<E> head;
15
+
privateNode<E> tail;
14
16
//constructer for class.. here we will make a dummy node for circly linked list implementation with reduced error catching as our list will never be empty;
15
17
publicCircleLinkedList(){
16
-
//creation of the dummy node
17
-
head = newNode<E>(null,head);
18
-
size = 0;
18
+
head = newNode<>(null, head);
19
+
tail = head;
19
20
}
20
21
// getter for the size... needed because size is private.
21
22
publicintgetSize(){ returnsize;}
@@ -25,9 +26,13 @@ public void append(E value){
25
26
// we do not want to add null elements to the list.
26
27
thrownewNullPointerException("Cannot add null element to the list");
27
28
}
28
-
//head.next points to the last element;
29
-
head.next = newNode<E>(value,head);
30
-
size++;}
29
+
30
+
//add new node at the end of the list and update tail node to point to new node
0 commit comments