import queue
# 1.普通q
# 2.先进后出q
# 3.优先级q
普通Queue
q=queue.Queue(3)
q.put(1)
q.put(2)
q.put(3)
print(q.get())
print(q.get())
print(q.get())
输出:
1
2
3
# 先进后出,堆栈式队列
q = queue.LifoQueue(5)
q.put(1)
q.put(2)
q.put(3)
q.put(4)
print(q.get())
输出:
4
# 优先级Queue
q = queue.PriorityQueue()
q.put((10,'a'))
q.put((-1,'b'))
q.put((100,'c'))
print(q.get())
print(q.get())
print(q.get())
输出:
"b"
"a"
"c"