//For better O.O design this should be private allows for better black box design
privateintsize;
//this will point to dummy node;
privateNode<E>head;
//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;
publicCircleLinkedList(){
//creation of the dummy node
head=newNode<E>(null,head);
size=0;
}
// getter for the size... needed because size is private.
publicintgetSize(){
returnsize;
}
// 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.
publicvoidappend(Evalue){
if(value==null){
// we do not want to add null elements to the list.
thrownewNullPointerException("Cannot add null element to the list");
}
//head.next points to the last element;
head.next=newNode<E>(value,head);
size++;
}
publicEremove(intpos){
if(pos>size||pos<0){
//catching errors
thrownewIndexOutOfBoundsException("position cannot be greater than size or negative");
}
Node<E>iterator=head.next;
//we need to keep track of the element before the element we want to remove we can see why bellow.