logo Practice-It logo

wrapHalf

Language/Type: Java collections Deque
Author: Marty Stepp (on 2013/01/29)

Write a method named wrapHalf that accepts a Deque of integers as a parameter and modifies its contents so that the elements in the last half of the deque are rearranged to be in the front of the deque in the same order. After a call to your method, the element that used to be the first in the second half of the deque will be the first overall element in the deque. If the deque is of odd size, consider the last half of the deck to include the middle element. Do not use any other collections or arrays as auxiliary storage.

For example, if passed the deque [1, 2, 3, 4, 5, 6, 7, 8], your method should change it to [5, 6, 7, 8, 1, 2, 3, 4]. This method should run in O(N) time for a deque of N elements.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

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.