Import Queue as Q def priorityqueue_int (): = Q.priorityqueue ( que.put) que.put(1) que.put (5) while not que.empty (): Print (Que.get ()) Priorityqueue_int () " " first pop up 1, then 5, last " "
ImportQueue as QclassSkill (object):def __init__(self,priority,description): Self.priority=Priority Self.description=Descriptiondef __lt__(self,other):returnSelf.priority <other.prioritydef __str__(self):return '('+ STR (self.priority) +', \ ''+ Self.description +'\ ')'defpriorityqueue_class (): Que=Q.priorityqueue () que.put (Skill (7,'proficient7')) Que.put (Skill (5,'proficient5')) Que.put (Skill (6,'Proficient6')) Que.put (Skill (10,'expert')) Que.put (Skill (1,'Novice')) Print('End') while notque.empty ():Print(Que.get ()) Priorityqueue_class ()" "When the elements of a queue are custom, we need to define a comparison rule in the element's class" "
Python Queue priority queue