Skip to content

Commit 888b054

Browse files
committed
simple-linked-list: simplify example implementation
1 parent 05bc1f7 commit 888b054

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

‎exercises/simple-linked-list/src/example/java/SimpleLinkedList.java‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import java.util.NoSuchElementException;
44
import java.util.Objects;
55

6-
public class SimpleLinkedList<T> {
6+
class SimpleLinkedList<T> {
77

88
private static class Element<T> {
99

1010
final T value;
11-
Element next;
11+
Element<T> next;
1212

1313
Element(T value) {
1414
this.value = value;
@@ -18,16 +18,16 @@ private static class Element<T> {
1818
private Element<T> head;
1919
private int size;
2020

21-
public SimpleLinkedList() {
21+
SimpleLinkedList() {
2222
}
2323

24-
public SimpleLinkedList(T[] values) {
25-
for (int ii = values.length - 1; ii >= 0; ii--) {
26-
push(values[ii]);
24+
SimpleLinkedList(T[] values) {
25+
for (int i = values.length - 1; i >= 0; i--) {
26+
push(values[i]);
2727
}
2828
}
2929

30-
public final void push(T value) {
30+
final void push(T value) {
3131
Element<T> newElement = new Element<>(value);
3232
this.size++;
3333
if (Objects.isNull(head)) {
@@ -38,7 +38,7 @@ public final void push(T value) {
3838
}
3939
}
4040

41-
public T pop() {
41+
T pop() {
4242
if (Objects.isNull(head)) {
4343
throw new NoSuchElementException();
4444
}
@@ -48,7 +48,7 @@ public T pop() {
4848
return value;
4949
}
5050

51-
public void reverse() {
51+
void reverse() {
5252
Element<T> current = head;
5353
Element<T> next;
5454
Element<T> previous = null;
@@ -61,8 +61,8 @@ public void reverse() {
6161
head = previous;
6262
}
6363

64-
public T[] asArray(Class<T> clazz) {
65-
T[] result = newArray(clazz, this.size);
64+
T[] asArray(Class<T> clazz) {
65+
T[] result = newArray(clazz, size);
6666
int index = 0;
6767
Element<T> current = head;
6868
while (Objects.nonNull(current)) {
@@ -72,14 +72,14 @@ public T[] asArray(Class<T> clazz) {
7272
return result;
7373
}
7474

75-
private <T> T[] newArray(Class<T> clazz, int size) {
75+
private T[] newArray(Class<T> clazz, int size) {
7676
@SuppressWarnings("unchecked")
7777
T[] arr = (T[]) Array.newInstance(clazz, size);
7878

7979
return arr;
8080
}
8181

82-
public int size() {
82+
int size() {
8383
return this.size;
8484
}
8585
}

0 commit comments

Comments
 (0)