import java.util.ArrayList;

public class ArrayQueue implements Queue 
{
	private ArrayList queue;
	
    public ArrayQueue()
    {
        queue = new ArrayList();
    } 
	
    public void enqueue(Object x)
    {
        queue.add(x);
    }
    
    public Object dequeue()
    {
        return queue.remove(0);
    }
    
    public Object peekFront()
    {
        return queue.get(0);
    }
    
    public boolean isEmpty()
    {
        return queue.size() == 0;
    }
    
    public String toString()
    {
    	return queue.toString();
    }
    
    public java.util.Iterator iterator()
	{
		return new Elements();
	}
	
	
	// inner class to implement iterator over list
	class Elements implements java.util.Iterator
	{
		private int index = 0;
		
		public boolean hasNext()
		{
			return index < queue.size();
		}
		
		public Object next()
		{
			Object result = null;
			
			if (hasNext())
			{
				result = queue.get(index);
				index++;
				return result;
			}
			else
				throw new java.util.NoSuchElementException();
		}
		
		public void remove()
		{
			throw new UnsupportedOperationException();
		}
			
    }
    
    
    public static void main(String[] args)
    {
    	Queue q = new ArrayQueue();
    	q.enqueue(new Integer(9));
    	q.enqueue(new Integer(10));
    	q.enqueue(new Double(8));	// after all, it's a queue of Objects
    	q.enqueue("hoser");
    	System.out.println(q);
    }
} 
