import java.util.LinkedList;
import java.util.NoSuchElementException;
/**
 * Simple implementation of a Queue using a Linked List.
 * @param <K>
 * @author CIS-121 Staff
 * @version 1.0 10/17/08
 * @see MyQueueI
 */
public class MyGoodQueue<K> implements MyQueueI<K> {
	private final LinkedList<K> list;
	
	public MyGoodQueue(){
		list = new LinkedList<K>();
	}

	/**
	 * Returns the element at the front of the queue
	 * without removing it.
	 * 
	 * @return element at the front of this queue
	 */
	public K peek() throws NoSuchElementException{
		if(isEmpty()) {
			throw new NoSuchElementException();
		}else {
			return list.peek();
		}
	}

	/**
	 * Adds the specified element e at the back of this queue.
	 * @param k
	 */
	public void enqueue(final K k) {
		list.add(k);
	}

	/**
	 * Deletes and returns the element at the front of this queue.
	 * @return element at the front of this queue
	 */
	public K dequeue() throws NoSuchElementException{
		if(isEmpty())
			throw new NoSuchElementException();
		else
			return list.poll();
	}

	/**
	 * Tests if this queue is empty.
	 * @return True on empty false otherwise.
	 */
	public boolean isEmpty() {
		if(list.isEmpty())
			return true;
		return false;
	}
}

