-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDLL.java
More file actions
65 lines (64 loc) · 1.53 KB
/
DLL.java
File metadata and controls
65 lines (64 loc) · 1.53 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
56
57
58
59
60
61
62
63
64
65
public class DLL<T> {
private DLLNode<T> head;
private DLLNode<T> current;
public DLL() {
head = current = null;
}
public boolean empty() {
return head == null;
}
public boolean last() {
return current.next == null;
}
public boolean first() {
return current.previous == null;
}
public boolean full() {
return false;
}
public void findFirst() {
current = head;
}
public void findNext() {
current = current.next;
}
public void findPrevious() {
current = current.previous;
}
public T retrieve() {
return current.data;
}
public void update(T val) {
current.data = val;
}
public void insert(T val) {
DLLNode<T> tmp = new DLLNode<T>(val);
if(empty()) {
current = head = tmp;
}
else {
tmp.next = current.next;
tmp.previous = current;
if(current.next != null)
current.next.previous = tmp;
current.next = tmp;
current = tmp;
}
}
public void remove() {
if(current == head) {
head = head.next;
if(head != null)
head.previous = null;
}
else {
current.previous.next = current.next;
if(current.next != null)
current.next.previous = current.previous;
}
if(current.next == null)
current = head;
else
current = current.next;
}
}