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
privateintsize; //For better O.O design this should be private allows for better black box design
11
-
privateNode<E> head; //this will point to dummy node;
12
-
publicCircleLinkedList(){ //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;
13
-
head = newNode<E>(null,head); //creation of the dummy node
10
+
//For better O.O design this should be private allows for better black box design
11
+
privateintsize;
12
+
//this will point to dummy node;
13
+
privateNode<E> head;
14
+
//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
+
publicCircleLinkedList(){
16
+
//creation of the dummy node
17
+
head = newNode<E>(null,head);
14
18
size = 0;
15
19
}
16
-
publicintgetSize(){ returnsize;} // getter for the size... needed because size is private.
17
-
publicvoidappend(Evalue){ // for the sake of simplistiy this class will only contain the append function or addLast other add functions can be implemented however this is the basses of them all really.
20
+
// getter for the size... needed because size is private.
21
+
publicintgetSize(){ returnsize;}
22
+
// for the sake of simplistiy this class will only contain the append function or addLast other add functions can be implemented however this is the basses of them all really.
23
+
publicvoidappend(Evalue){
18
24
if(value == null){
19
-
thrownewNullPointerException("Cannot add null element to the list"); // we do not want to add null elements to the list.
25
+
// we do not want to add null elements to the list.
26
+
thrownewNullPointerException("Cannot add null element to the list");
20
27
}
21
-
head.next = newNode<E>(value,head); //head.next points to the last element;
28
+
//head.next points to the last element;
29
+
head.next = newNode<E>(value,head);
22
30
size++;}
23
31
publicEremove(intpos){
24
32
if(pos>size || pos< 0){
25
-
thrownewIndexOutOfBoundsException("position cannot be greater than size or negative"); //catching errors
33
+
//catching errors
34
+
thrownewIndexOutOfBoundsException("position cannot be greater than size or negative");
26
35
}
27
36
Node<E> iterator = head.next;
28
-
Node<E> before = head; //we need to keep track of the element before the element we want to remove we can see why bellow.
37
+
//we need to keep track of the element before the element we want to remove we can see why bellow.
38
+
Node<E> before = head;
29
39
for(inti = 1; i<=pos; i++){
30
40
iterator = iterator.next;
31
41
before = before.next;
32
42
}
33
43
Esaved = iterator.value;
34
-
before.next = iterator.next; // assigning the next referance to the the element following the element we want to remove... the last element will be assigned to the head.
35
-
iterator.next = null; // scrubbing
44
+
// assigning the next referance to the the element following the element we want to remove... the last element will be assigned to the head.
0 commit comments