import queue
q = queue.Queue() #模拟队列,先进先出
q.put('first')
q.put('second')
q.put('third') print(q.get())
print(q.get())
print(q.get())
模拟队列
import queue
q = queue.LifoQueue() #模拟堆栈,先进后出
q.put('first')
q.put('second')
q.put('third') print(q.get())
print(q.get())
print(q.get())
模拟堆栈
import queue
q = queue.PriorityQueue() #put进去一个元组,第一个元素设置优先级,越小越高
q.put((10,'first'))
q.put((30,'second'))
q.put((20,'third')) print(q.get())
print(q.get())
print(q.get())
设置优先级