from collections import deque
# 双端队列的特点,后进的总是在两边。从两边压入导致先进去的会在中间
# 双端队列的底层使用链表结构,所以insert 和 remove操作效率 远远高于列表
dq = deque()
# 默认append从右边压入
dq.append(1)
dq.append(2)
dq.appendleft('a')
print(dq) # deque(['a', 1, 2])

# 默认pop从右边弹出,可用dq.popleft()从左边弹出
print(dq.pop())

 

相关文章:

  • 2021-07-30
  • 2022-12-23
  • 2021-09-22
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
猜你喜欢
  • 2022-12-23
  • 2021-12-21
  • 2021-10-20
相关资源
相似解决方案