left
and right
.pushFront
, add the element to the front of left
.pushBack
, add the element to the back of right
.pushMiddle
, if left
has more elements, move the last element of left
to the front of right
, then add the new element to the back of left
. Otherwise, add the new element to the front of right
.popFront
, if left
is empty, return -1
. Otherwise, pop from the front of left
and balance the deques if necessary.popMiddle
, if the total size is even, pop from the back of left
; if odd, pop from the front of right
. Balance the deques if necessary.popBack
, if right
is empty, pop from the back of left
. Otherwise, pop from the back of right
.