import java.util.ArrayList;
import java.util.List;

public class ArrayPriorityQueue implements PriorityQueue 
{ 
    public ArrayPriorityQueue()
    {
        items = new ArrayList();
    } 

    public void add(Object x)
    {
        items.add(x);
    } 

    /**
     * Removes and returns a minimal element of this pq
     * @return a minimal element after removing it
     */
    
    public Object removeMin() 
    {
        Object min = peekMin();
	items.remove(min);
	return min;
    }

    /**
     * Returns a minimal element of this pq
     * @return a minimal element
     */
    
    public Object peekMin() 
    { 
        int minIndex = 0; 
        for (int i = 1; i < items.size(); i++) {
	    Comparable c = (Comparable) items.get(i);
            if (c.compareTo(items.get(minIndex)) < 0) { 
                minIndex = i; 
            } 
        } 
        return items.get(minIndex); 
    } 

    public boolean isEmpty()
    {
        return items.size() == 0;
    } 

    private List items; 
} 
