The.
This commit is contained in:
@@ -17,26 +17,20 @@ class Examples {
|
||||
}
|
||||
|
||||
// A doubly-linked list element.
|
||||
abstract class ANode<PointsTo> {
|
||||
abstract class ANode<T> {
|
||||
|
||||
PointsTo nxt; // Next element.
|
||||
PointsTo pre; // Previous element.
|
||||
ANode<T> nxt; // Next element.
|
||||
ANode<T> pre; // Previous element.
|
||||
|
||||
ANode(PointsTo nxt, PointsTo pre) {
|
||||
ANode(ANode<T> nxt, ANode<T> pre) {
|
||||
this.nxt = nxt;
|
||||
this.pre = pre;
|
||||
}
|
||||
}
|
||||
|
||||
// Self-referential node.
|
||||
abstract class ASRefNode {
|
||||
|
||||
ASRefNode nxt;
|
||||
ASRefNode pre;
|
||||
|
||||
ASRefNode() {
|
||||
this.nxt = this;
|
||||
this.pre = this;
|
||||
void assignNode(ANode<T> nxt, ANode<T> pre) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Can't call assignNode() on non-Node."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +46,10 @@ class Deque<A> {
|
||||
class Sentinel<T> extends ANode<ANode<T>> {
|
||||
|
||||
Sentinel() {
|
||||
// To create an empty list, this Sentinel points to itself.
|
||||
super(null, null);
|
||||
this.nxt = this;
|
||||
this.pre = this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,4 +61,15 @@ class Node<T> extends ANode<Node<T>> {
|
||||
super(null, null);
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
Node(T val, ANode<T> nxt, ANode<T> pre) {
|
||||
this(val);
|
||||
this.assignNode(nxt, pre);
|
||||
}
|
||||
|
||||
void assignNode(ANode<T> nxt, ANode<T> pre) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Can't call assignNode() on non-Node."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user