public class LinkedQueue
private static class Elem
private T value;
private Elem
private Elem(T value, Elem
this.value = value;
this.next = next;
}
}
private Elem
private Elem
public E peek() {
return front.value;
}
public void enqueue(E value) {
Elem
newElem = new Elem
if (rear == null) {
front = rear = newElem;
} else {
rear.next = newElem;
rear = newElem;
}
}
public E dequeue() {
E result = front.value;
if (front != null & front.next == null) {
front = rear = null;
} else {
front = front.next;
}
return result;
}
public boolean isEmpty() {
return front == null;
}
}