C++ 中优先级队列的结构排序条件
Struct ordering criteria of a priority queue in C++
我想知道是否可以使用相同的结构但具有不同排序标准的两种不同的priority_queues(stl(进行排序。想象一下:
struct stuff {
int a, b;
}
priority_queue<stuff> a;
priority_queue<stuff> b;
请注意,这不是C++的功能代码,只是伪代码。然后,我想知道 a 和 b 的顺序是否有可能不同,一个在队列开始时有最大的 stuff.a,另一个在队列开始时有最大的 stuff.b。
谢谢!
马克
std::p riority_queue 上的文档有一个如何使用 lambda 的示例,因此只需创建其中的 2 个:
struct stuff {
int a, b;
};
void foo()
{
auto cmpBiggerA = []( const stuff &s1, const stuff &s2 ) { return s1.a > s2.a; };
auto cmpBiggerB = []( const stuff &s1, const stuff &s2 ) { return s1.b > s2.b; };
priority_queue<stuff,std::vector<stuff>,decltype(cmpBiggerA)> a( cmpBiggerA );
priority_queue<stuff,std::vector<stuff>,decltype(cmpBiggerB)> b( cmpBiggerB );
}
相关文章:
- 将结构向量排序为子组
- 带有枚举方向/类型的气泡排序结构数组
- C++对结构向量进行排序
- 在C++中对结构向量进行排序时出现问题
- 按字母顺序对结构内数组变量中的名称进行排序
- 保持排序的数据结构,允许log N插入时间,并且可以返回我在log N中查找的元素的索引
- 使用选择排序对数组数据结构进行排序,但它不起作用
- 对结构向量进行两次排序
- C++使用QuickSort对数组结构进行排序
- 如何选择排序一些结构
- 对结构int成员进行排序
- 在排序链表中插入结构并将其写入二进制文件
- 对坐标结构的向量进行排序
- C++ 中优先级队列的结构排序条件
- C++ MDC final-在字符类型的数组结构中按字母顺序对记录中的名称进行排序
- 按字母顺序对结构数组进行排序
- C++结构排序性能
- 自定义结构排序不起作用
- std::向量使结构排序变慢?C++
- 数据结构-排序队列链表c++