CS计算机代考程序代写 public class LinkedQueue implements Queue {

public class LinkedQueue implements Queue {

private static class Elem {

private T value;
private Elem next;

private Elem(T value, Elem next) {
this.value = value;
this.next = next;
}
}

private Elem front;
private Elem rear;

public E peek() {
return front.value;
}

public void enqueue(E value) {
Elem newElem;
newElem = new Elem(value, null );

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;
}

}