package deque;

import tester.Tester;

class Examples {

    Sentinel<String> exampleSentinel;

    void init() {
        exampleSentinel = new Sentinel<String>();
    }

    void testSentinel(Tester t) {
        init();
        t.checkExpect(exampleSentinel.nxt, exampleSentinel);
    }
}

// A doubly-linked list element.
abstract class ANode<PointsTo> {

    PointsTo nxt; // Next element.
    PointsTo pre; // Previous element.

    ANode(PointsTo nxt, PointsTo pre) {
        this.nxt = nxt;
        this.pre = pre;
    }
}

// Self-referential node.
abstract class ASRefNode {

    ASRefNode nxt;
    ASRefNode pre;

    ASRefNode() {
        this.nxt = this;
        this.pre = this;
    }
}

class Deque<A> {

    Sentinel<A> sentinel;

    Deque(Sentinel<A> sentinel) {
        this.sentinel = sentinel;
    }
}

class Sentinel<T> extends ANode<ANode<T>> {

    Sentinel() {
        super(null, null);
        this.nxt = this;
    }
}

class Node<T> extends ANode<Node<T>> {

    T val;

    Node(T val) {
        super(null, null);
        this.val = val;
    }
}
