-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentinel.java
More file actions
58 lines (58 loc) · 1.52 KB
/
Copy pathSentinel.java
File metadata and controls
58 lines (58 loc) · 1.52 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
class Sentinel<T> extends ANode<T> {
//empty constructor
Sentinel() {
this.next = this;
this.prev = this;
}
//returns this deques's size
int countSize() {
return this.next.countSizeHelp();
}
//helper for countSize()
int countSizeHelp() {
return 0;
}
//adds given item at the beginning of this list
void addAtHead(T t) {
new Node<T>(t, this, this.next);
}
//adds given item at the end of this list
void addAtTail(T t) {
new Node<T>(t, this.prev, this);
}
//removes item from beginning of this list
T removeFromHead() {
if (this.next == this) {
throw new RuntimeException("This list is already empty!");
}
else {
return this.next.remove();
}
}
//removes item from end of this list
T removeFromTail() {
return this.prev.remove();
}
//removes item from this list
T remove() {
throw new RuntimeException("This list is already empty!");
}
//finds item in this list based on given pred
ANode<T> find(IPred<T> pred) {
return this.next.findHelp(pred);
}
//helper for find
ANode<T> findHelp(IPred<T> pred) {
return this;
}
//helper for removeNode
void removeNodeHelp(ANode<T> n, Boolean check) {
if (!check) {
this.next.removeNodeHelp(n, true);
}
}
//checks if this node's data is the same as given data
boolean sameNode(T that) {
return false;
}
}