一、什么是队列?
定义:
二、队列的实现
1、单向队列
from collections import deque q = deque() q.append(1) q.append(2) q.append(3) print(q.popleft())
输出结果
"D:Program FilesPython35python3.exe" E:/test/queue.py 1 Process finished with exit code 0
2、内置队列操作文件(相当于linux的tail功能)
1、代码
from collections import deque f = open('test','r') q = deque(f,3) for line in q: print(line)
2、test
12 456fsddsg 7890 45345 768678 sfs tutrur hghfj wtwet yutyuytu qwrwrweret hhrthret
3、输出结果
"D:Program FilesPython35python3.exe" E:/BaiduNetdiskDownload/0921/test/queue.py yutyuytu qwrwrweret hhrthret Process finished with exit code 0
三、队列的实现原理