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)