def popFront(self) -> int: if self.length == 0: return -1
val = 0 if self.length == 1: val = self.right_half.pop() else: val = self.left_half.popleft() if len(self.right_half) - len(self.left_half) > 1: self.left_half.append(self.right_half.popleft()) self.length -= 1 return val
def popMiddle(self) -> int: if self.length == 0: return -1
val = 0 if len(self.left_half) >= len(self.right_half): val = self.left_half.pop() if len(self.right_half) - len(self.left_half) > 1: self.left_half.append(self.right_half.popleft()) else: val = self.right_half.popleft() if len(self.left_half) - len(self.right_half) >= 1: self.right_half.appendleft(self.left_half.pop()) self.length -= 1 return val
def popBack(self) -> int: if self.length == 0: return -1
val = self.right_half.pop() if len(self.left_half) - len(self.right_half) >= 1: self.right_half.appendleft(self.left_half.pop()) self.length -= 1 return val
# Your FrontMiddleBackQueue object will be instantiated and called as such: # obj = FrontMiddleBackQueue() # obj.pushFront(val) # obj.pushMiddle(val) # obj.pushBack(val) # param_4 = obj.popFront() # param_5 = obj.popMiddle() # param_6 = obj.popBack()