Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

dequeMystery1

Language/Type: Java Deque Deque mystery collections
Author: Conor Reisman (on 2013/01/29)

What are the contents of the Deque returned by each of the following calls? Write the deque's contents from the client perspective as they would appear by a call to the toString method.

public static Deque mystery(String[] elements) {
    Deque<String> deque = new LinkedList<String>();
    for (int i = 0; i < elements.length; i++) {
        if (i % 3 == 0) {
            deque.addLast(elements[i]);
        } else {
            deque.addFirst(elements[i]);
        }
    }
    return deque;
}

Write the output produced by the method when passed each of the following Deques:

["fee", "fie", "foe", "fum"]
["Dana", "Jake", "Sara", "Mikey", "Janette", "Conor", "April"]
["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"]

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.