Skip to content

Commit 6afdadd

Browse files
committed
refactor indentation
1 parent 52f7e4e commit 6afdadd

File tree

1 file changed

+49
-51
lines changed

1 file changed

+49
-51
lines changed
Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
11
public class CircleLinkedList<E>{
2-
private static class Node<E>{
3-
Node<E> next;
4-
E value;
5-
private Node(E value, Node<E> next){
6-
this.value = value;
7-
this.next = next;
8-
}
9-
}
10-
//For better O.O design this should be private allows for better black box design
11-
private int size;
12-
//this will point to dummy node;
13-
private Node<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-
public CircleLinkedList(){
16-
//creation of the dummy node
17-
head = new Node<E>(null,head);
18-
size = 0;
19-
}
20-
// getter for the size... needed because size is private.
21-
public int getSize(){ return size;}
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-
public void append(E value){
24-
if(value == null){
25-
// we do not want to add null elements to the list.
26-
throw new NullPointerException("Cannot add null element to the list");
27-
}
28-
//head.next points to the last element;
29-
head.next = new Node<E>(value,head);
30-
size++;}
31-
public E remove(int pos){
32-
if(pos>size || pos< 0){
33-
//catching errors
34-
throw new IndexOutOfBoundsException("position cannot be greater than size or negative");
35-
}
36-
Node<E> iterator = head.next;
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;
39-
for(int i = 1; i<=pos; i++){
2+
private static class Node<E>{
3+
Node<E> next;
4+
E value;
5+
private Node(E value, Node<E> next){
6+
this.value = value;
7+
this.next = next;
8+
}
9+
}
10+
//For better O.O design this should be private allows for better black box design
11+
private int size;
12+
//this will point to dummy node;
13+
private Node<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+
public CircleLinkedList(){
16+
//creation of the dummy node
17+
head = new Node<E>(null,head);
18+
size = 0;
19+
}
20+
// getter for the size... needed because size is private.
21+
public int getSize(){ return size;}
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+
public void append(E value){
24+
if(value == null){
25+
// we do not want to add null elements to the list.
26+
throw new NullPointerException("Cannot add null element to the list");
27+
}
28+
//head.next points to the last element;
29+
head.next = new Node<E>(value,head);
30+
size++;}
31+
public E remove(int pos){
32+
if(pos>size || pos< 0){
33+
//catching errors
34+
throw new IndexOutOfBoundsException("position cannot be greater than size or negative");
35+
}
36+
Node<E> iterator = head.next;
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;
39+
for(int i = 1; i<=pos; i++){
4040
iterator = iterator.next;
41-
before = before.next;
42-
}
43-
E saved = iterator.value;
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.
45-
before.next = iterator.next;
46-
// scrubbing
47-
iterator.next = null;
48-
iterator.value = null;
49-
return saved;
50-
51-
}
52-
53-
}
41+
before = before.next;
42+
}
43+
E saved = iterator.value;
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.
45+
before.next = iterator.next;
46+
// scrubbing
47+
iterator.next = null;
48+
iterator.value = null;
5449

50+
return saved;
51+
}
52+
}

0 commit comments

Comments
 (0)