public class SingleList {
    private SingleNode dumHead; // dummy
    private SingleNode tail; // not dummy
    public int length; // exclude dummy head and tail

    public SingleList() {
        dumHead = new SingleNode(0);
        length = 0;
    }

    public boolean isEmpty() {
        return length == 0;
    }

    public SingleNode head() {
        if (length == 0) {
            return null;
        }
        return dumHead.next;
    }

    public void insertAfter(SingleNode newNode, SingleNode position) {
        SingleNode temp = position.next;
        position.next = newNode;
        newNode.next = temp;
        length++;
    }

    public void insertAtHead(SingleNode node) {
        insertAfter(node, dumHead);
    }

    public void insertAtTail(SingleNode node) {
        insertAfter(node, tail);
    }


}
