public class Queue {
    // Implementation of the ADT Queue
    // The Queue access is not synchronized here.

    static class Node {
        Object data;
        Node link;
        Node(Object elem, Node tail) {
            data = elem;
            link = tail;
        }
    }

    private Node head; // the oldest queue element, if any;
    private Node tail; // the youngest queue element, if any

    public boolean empty() {
        return head == null;
    }

    public void enqueue(Object elem) {
        Node x = new Node(elem, null);

        if (head == null) {
            head = x;
            tail = x;
        } else {
            tail.link = x;
            tail = tail.link;
        }
    }

    public void dequeue() {
        if (head != null) {
            head = head.link;
        } 
        if (head == null) {
            tail = null;
        }
    }

    public Object front() {
        if (head != null) { 
            return head.data;
        } else {
            return null;
        }
    }
}

