public class StackandQueue
{
    /**
     * Returns the minimal element in a stack of Strings leaving the
     * stack unchanged when the function returns.
     * @param stack the stack of Strings
     * @return the lexicographically smallest String in stack
     */
    public static String findMin(Stack stack)
    {
		String min = (String) stack.pop();
		Stack copy = new ArrayStack();
		copy.push(min);
		while (! stack.isEmpty())
		{
			String str = (String) stack.pop();
			if (str.compareTo(min) < 0)
				min = str;
			copy.push(str);
		}
		stack = copy;
		return min;
	}

	/**
	 * Returns an ArrayList containing elements in s with the
	 * first element of the ArrayList the first (bottom) element
	 * of s.  Leaves s unchanged when the function returns.
	 * @param s the stack
	 * @return an ArrayList with the elements of s (top of s is at end of ArrayList)
	 */
	/*public static ArrayList stackToList(Stack s)
	{

	}
    */

    /**
     * Reverses the order of the elements in q, runs in O(n)
     * time for an n-element Queue.
     * @param q the queue
     */
    public static void reverse(Queue q)
    {

    }

    public static void main(String args[])
    {
		String[] list = {"zebra", "monkey", "tiger", "dog", "elephant"};
		if (args.length > 1)
			list = args;

		Stack s = new ArrayStack();
		for(int k=0; k < list.length; k++)
			s.push(list[k]);

		String min = findMin(s);
		System.out.println("min = " + min);
		System.out.println("here's the stack:");
		if (s.isEmpty())
			System.out.println("Empty!");
		while (! s.isEmpty())
	    	System.out.println(s.pop());

	    Queue q = new ListQueue();
	    for(int k=0; k < list.length; k++)
			q.enqueue(list[k]);
		System.out.println("\nOriginal queue: " + q);
		reverse(q);
		System.out.println("Reversed queue: " + q);
    }
}
