import java.util.Stack;
import java.util.NoSuchElementException;

/**
 * Simple and buggy implementation of a Queue, using two Stacks.
 * The bottom of the left stack is at the front of the queue.
 * 
 * @author CIS-121 Staff
 * @version 1.0 10/17/08
 * @param <K>
 * @see MyQueueI
 */

public class MyBadQueue<K> implements MyQueueI<K> {

	private Stack<K> left;
	private Stack<K> right;
	
	public MyBadQueue(){
		left = new Stack<K>();
		right = new Stack<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(left.empty()) {
			throw new NoSuchElementException();
		}

		return left.peek();
	}

	/**
	 * Adds the specified element e at the back of this queue.
	 * @param k
	 */
	public void enqueue(final K k) {
		while(!left.empty()) {
			right.push((left.pop()));
		}

		left.push(k);

		while(!right.isEmpty()) {
			left.push((right.pop()));
		}
	}

	/**
	 * 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 (left.empty())
			throw new NoSuchElementException();

		for(int i = 0; i < left.size()-1; i++){
			right.push(left.peek());
		}
		final K to_return = right.pop();

		return to_return;
	}

	/**
	 * Tests if this queue is empty.
	 * @return True on empty false otherwise.
	 */
	public boolean isEmpty() {
		boolean isEmpty = false;
		boolean[] sizeCheck = new boolean[left.size()];
		for(int ii = 0; ii < sizeCheck.length -1; ii++)
			 isEmpty = true;
		return isEmpty;
	}
}

