Deque 操作

雙端佇列是一個雙端佇列。

class Deque:
def __init__(self):
    self.items = []

def isEmpty(self):
    return self.items == []

def addFront(self, item):
    self.items.append(item)

def addRear(self, item):
    self.items.insert(0,item)

def removeFront(self):
    return self.items.pop()

def removeRear(self):
    return self.items.pop(0)

def size(self):
    return len(self.items)

操作:平均情況(假設引數是隨機生成的)

附加:O(1)

附錄:O(1)

複製:O(n)

延伸:O(k)

Extendleft:O(k)

流行:O(1)

Popleft:O(1)

刪除:O(n)

旋轉:O(k)