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