(priority_queue)自定义优先级

217 篇文章 13 订阅
本文介绍了如何利用优先级队列解决具体问题,包括Windows消息队列模拟和医院病人优先级处理。在C++中,通过自定义比较函数实现优先级队列,并解释了优先级队列的工作原理及其在不同场景下的应用。
摘要由CSDN通过智能技术生成

思考与总结:

1.优先队列,先出队列元素不是先进队列的元素,而是队列中优先级最高的元素
2.遇到这种题一般把每一个数据封装到一个struct里
3.然后根据优先级判断依据,我们通过重定向定义优先队列的优先级
如果我们写bool operator <
下面return里a< b,意味着a的值比b小的话,优先级小
4.我们把数据输入优先队列里,那队列里就自动为我们排好序了
输出的时候,取队列顶端,就把优先级大的取出来了

题目1:

Message queue is the basic fundamental of windows system. For each process, the system maintains a message queue. If something happens to this process, such as mouse click, text change, the system will add a message to the queue. Meanwhile, the process will do a loop for getting message from the queue according to the priority value if it is not empty. Note that the less priority value means the higher priority. In this

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

每天学点

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值