python 优先队列
from queue import PriorityQueue q = PriorityQueue() q.put((2, 'code'))
q.put((1, 'eat'))
q.put((3, 'sleep')) while not q.empty():
next_item = q.get()
print(next_item) # Result:
# (1, 'eat')
# (2, 'code')
# (3, 'sleep')
python 优先队列
from queue import PriorityQueue q = PriorityQueue() q.put((2, 'code'))
q.put((1, 'eat'))
q.put((3, 'sleep')) while not q.empty():
next_item = q.get()
print(next_item) # Result:
# (1, 'eat')
# (2, 'code')
# (3, 'sleep')