-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.java
More file actions
55 lines (54 loc) · 1.23 KB
/
LinkedList.java
File metadata and controls
55 lines (54 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public class LinkedList<T> implements List<T>{
private Node<T> head;
private Node<T> current;
public LinkedList() {
head = current = null;
}
public boolean empty() {
return head == null;
}
public boolean last() {
return current.next == null;
}
public boolean full() {
return false;
}
public void findFirst() {
current = head;
}
public void findNext() {
current = current.next;
}
public T retrieve() {
return current.data;
}
public void update(T e) {
current.data = e;
}
public void insert(T e) {
if (empty()) {
current = head = new Node<T>(e);
} else {
Node<T> tmp = current.next;
current.next = new Node<T>(e);
current = current.next;
current.next = tmp;
}
}
public void remove() {
if (current == head) {
head = head.next;
} else {
Node<T> tmp = head;
while (tmp.next != current) {
tmp = tmp.next;
}
tmp.next = current.next;
}
if (current.next == null) {
current = head;
} else {
current = current.next;
}
}
}