优先级队列和结构
priority queue and structs
#include <iostream>
#include <queue>
using namespace std;
struct Call
{
Call( int callNum, long callTime, int callLength ) :
CallNum( callNum ), CallTime( callTime ), CallLength( callLength ) { }
int CallNum;
long CallTime;
int CallLength;
};
bool operator>( const Call& lhs, const Call& rhs ) {
return lhs.CallLength > rhs.CallLength;
}
ostream& operator<<( ostream& os, const Call& c ) {
os << c.CallNum << " " << c.CallTime << " " << c.CallLength;
return os;
}
int main()
{
priority_queue< Call, vector<Call>, greater<Call> > q;
q.push( Call( 1, 200, 150 ));
q.push( Call( 2, 300, 950 ));
q.push( Call( 3, 100, 450 ));
q.push( Call( 4, 150, 320 ));
unsigned i=0, n=q.size();
for ( i=0; i<n; ++i ) {
cout << q.top() << endl;
q.pop();
}
}
这是我的代码。我的问题是,当我使用q.top();
时,它会打印到屏幕callNum, callTime, callLength
。但我想单独使用它们。
我的意思是我怎样才能打印到屏幕只是呼叫时间? 例如:q.top(callTime);
还是别的什么? 谁能帮助我?
你只是在寻找:
cout << q.top().CallNum << endl;
等等?
相关文章:
- C++ 中优先级队列的结构排序条件
- 优先级经常更改的作业优先级队列的数据结构
- C++ 数据结构队列:使用 for 循环查找队列中最大的元素
- 从 STL 优先级队列C++ (QtCreator) 打印结构
- C 在标题文件中创建具有结构定义的结构的队列
- 在 stl 中迭代结构类型的队列
- 从指针队列访问结构的成员
- 使用提升库在队列和堆栈数据结构上保存和加载数据时出错
- 优先队列中的结构比较
- C 单例结构队列
- 我的字符串队列结构有什么问题?
- 结构类似优先级队列,但具有类似下界的内容
- 使用队列<结构时出现 SIGSEGV 错误 *>
- 工作线程队列的这种变体是某种模式或通用结构吗?
- 排序结构的队列
- 在队列中推动结构变量
- 指针指向结构的指针(优先队列)
- 尝试使用自定义类的结构中的变量创建该类的优先级队列
- 哪种数据结构最适合C++中的基本堆栈和队列
- 将包含指向该类型队列的指针的结构推送到队列上时发生运行时崩溃