C++ 标准模板库STL 优先级队列 priority_queue 使用方法与应用介绍(一) (三)

2014-11-24 02:27:58 · 作者: · 浏览: 6
y queue
q.push(66.6);
q.push(22.2);
q.push(44.4);

// read and print two elements
cout << q.top() << ' ';
q.pop();
cout << q.top() << endl;
q.pop();

// insert three more elements
q.push(11.1);
q.push(55.5);
q.push(33.3);

// skip one element
q.pop();

// pop and print remaining elements
while (!q.empty())
{
cout << q.top() << ' ';
q.pop();
}
cout << endl;
}
/******************
运行结果:
total: 5050

***********************************************
Popping out elements... 100 40 30 25

***********************************************
mypq.top() is now:--->>> you

***********************************************
66.6 44.4
33.3 22.2 11.1

Process returned 0 (0x0) execution time : 0.055 s
Press any key to continue.

********************/