public class Queue<E extends Object> {
private Node<E> head, tail;
private N;
private class Node<E> {
Node<E> next;
E value;
}
public void enqueue(E e) {
Node<E> oldTail = tail;
tail = new Node<>();
tail.value = e;
if(isEmpty()) head = tail;
else oldTail.next = tail;
N ++;
}
public boolean isEmpty() {return N == 0;}
public e dequeue() {
if(isEmpty()) return null;
E e = head.next;
N --;
if(isEmpty()) tail = null;
head = head.next;
return e;
}
}