入队出队

刘德胜 100次浏览

摘要:#-*-coding:UTF-8-*- fromcollectionsimportdeque queue=deque(["Eric","John","Michael"]) queue.append("Terry")#Terry入队 queue.append("...

# -*- coding: UTF-8 -*-
from collections import deque
queue = deque(["Eric", "John", "Michael"])
queue.append("Terry")           # Terry 入队
queue.append("Graham")          # Graham 入队
queue.popleft()                 # 队首元素出队
#输出: 'Eric'+
print(queue)
queue.popleft()                 # 队首元素出队
#输出: 'John'
print(queue)
queue                           # 队列中剩下的元素
#输出: deque(['Michael', 'Terry', 'Graham'])