package DataStructures; import java.util.NoSuchElementException; /** * A linked list implementation of a queue * @author Peter Williams */ public class QueueList implements Queue { private ListNode front; // read from here private ListNode back; // write to here public QueueList() { front = null; } public boolean isEmpty() { return front == null; } // join the back public void enqueue(Object item) { if (front == null) { front = back = new ListNode(item, null); } else { back = back.next = new ListNode(item, null); } } // leave the front public Object dequeue() { if (front == null) { throw new NoSuchElementException(); } else { Object item = front.data; front = front.next; return item; } } }