Python Queue priority queue

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.