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')

 

 

from:  https://dbader.org/blog/priority-queues-in-python

posted on 2018-12-17 16:06  Go_Forward  阅读(305)  评论(0编辑  收藏  举报