本文介绍了如何使STL的priority_queue固定大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的游戏,我使用 std :: priority_queue 小组提供命令

I am creating a simple game and I use std::priority_queue for giving commands to squads (every squad has a priority_queue<command>).

每20秒一个机器人会分析情况并发送命令到 priority_queue

Every 20 seconds a bot analyses the situation and sends commands to the priority_queue.

如何使 priority_queue 固定大小,例如,将大小设置为10?所需的效果是,当达到最大值时,如果我向队列中添加2个新命令,则会自动删除具有最低优先级的2个现有命令。

How can I make the priority_queue fixed-size, for example, set the size to 10? The desired effect is that when the maximum is reached, if I add 2 new commands to the queue, 2 existing commands with the lowest priority are automatically removed.

推荐答案

将它包装在另一个为您执行此操作的类中。该标准本身没有提供此类功能。

Wrap it in another class that will perform this operation for you. The Standard provides no such functionality on it's own.

这篇关于如何使STL的priority_queue固定大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 18:30