[Python3] DLL with middle node balancing
The main idea to move middle pointer to one position left/right or don\'t move. It depends on the current operation push/pop, position left/mid/right and the cu
##### The main idea to move middle pointer to one position left/right or don\'t move. It depends on the current operation `push/pop`, position `left/mid/right` and the current size `even/odd`. The simpliest way it\'s to take a paper and check all cases manually.  \n```python3 []\nclass Node:\n    def __init__(self, val = None):\n        self.val = val\n        self.prev = None\n        self.next = None\n\nclass FrontMiddleBackQueue:\n\n    def __init__(self):\n        self.size = 0\n        self.start = Node()\n        self.end = Node()\n        self.mid = self.start\n        self.start.next = self.end\n        self.end.prev = self.start\n        self.posLeft, self.posRight, self.posMiddle = \'left\', \'right\', \'mid\'\n\n    def pushFront(self, val: int) -> None:\n        node = Node(val)\n        left, right = self.start, self.start.next\n        node.prev, node.next = left, right\n        left.next, right.prev = node, node\n        self.__balanceMid(True, self.posLeft)\n\n    def pushMiddle(self, val: int) -> None:\n        node = Node(val)\n        if self.size & 1: # 1 -> 3 -> 2 => add 4 bofore 3\n            left, right = self.mid.prev, self.mid\n        else: # 1 -> 2 => add 3 after 1\n            left, right = self.mid, self.mid.next\n        \n        node.prev, node.next = left, right\n        left.next, right.prev = node, node\n        self.__balanceMid(True, self.posMiddle)\n\n    def pushBack(self, val: int) -> None:\n        node = Node(val)\n        left, right = self.end.prev, self.end\n        node.prev, node.next = left, right\n        left.next, right.prev = node, node\n        self.__balanceMid(True, self.posRight)\n\n    def popFront(self) -> int:\n        if self.isEmpty(): return -1\n        node = self.start.next\n        left, right = node.prev, node.next\n        left.next, right.prev = right, left\n        self.__balanceMid(False, self.posLeft)\n        return node.val\n\n    def popMiddle(self) -> int:\n        if self.isEmpty(): return -1\n        node = self.mid\n        left, right = node.prev, node.next\n        left.next, right.prev = right, left\n        self.__balanceMid(False, self.posMiddle)\n        return node.val\n        \n    def popBack(self) -> int:\n        if self.isEmpty(): return -1\n        node = self.end.prev\n        left, right = node.prev, node.next\n        left.next, right.prev = right, left\n        self.__balanceMid(False, self.posRight)\n        return node.val\n\n    def isEmpty(self) -> bool:\n        return self.size == 0\n\n    def __balanceMid(self, isAdd: bool, position: str):\n        if isAdd:\n            self.size += 1\n            match position:\n                case self.posMiddle:\n                    if self.size & 1:\n                        self.mid = self.mid.next\n                    else:\n                        self.mid = self.mid.prev\n                case self.posLeft:\n                    if self.size == 1:\n                        self.mid = self.mid.next\n                    elif self.size & 1 == 0:\n                        self.mid = self.mid.prev \n                case self.posRight:\n                    if self.size & 1:\n                        self.mid = self.mid.next\n        else:\n            self.size -= 1\n            if self.size == 0:\n                self.mid = self.start\n                return\n            match position:\n                case self.posMiddle:\n                    if self.size & 1:\n                        self.mid = self.mid.next\n                    else:\n                        self.mid = self.mid.prev\n                case self.posLeft:\n                    if self.size & 1:\n                        self.mid = self.mid.next\n                case self.posRight:\n                    if self.size & 1 == 0:\n                        self.mid = self.mid.prev\n        #self.printNodes()\n\n    def printNodes(self):\n        cur = self.start\n        values = []\n        while cur:\n            values.append(cur.val)\n            cur = cur.next\n        print(self.mid.val, [f\'{v}\' for v in values[1:-1]])\n```
['Doubly-Linked List', 'Python', 'Python3']