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.