本文整理汇总了C++中PriorityQueue::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ PriorityQueue::peek方法的具体用法?C++ PriorityQueue::peek怎么用?C++ PriorityQueue::peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue::peek方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
PriorityQueue<int> pq;
std::cout << pq.size() << std::endl;
pq.enqueue(1);
pq.present();
pq.enqueue(5);
pq.present();
pq.enqueue(9);
pq.present();
std::cout << pq.size() << " - " << pq.peek() << std::endl;
pq.enqueue(7);
pq.present();
pq.enqueue(3);
pq.present();
pq.enqueue(0);
pq.enqueue(10);
pq.present();
std::cout << pq.size() << " - " << pq.peek() << std::endl;
pq.dequeue();
pq.present();
pq.dequeue();
pq.present();
std::cout << pq.size() << " - " << pq.peek() << std::endl;
return 0;
}
示例2: main
/* main() manages the user interface;
* instantiates priority queue object, then operates loop to read input
* from user and call the appropriate priority queue method
*/
int main() {
PriorityQueue pq;
TokenScanner scanner;
while (true) {
string line = getLine("> ");
scanner.setInput(line);
scanner.ignoreWhitespace();
string cmd=scanner.nextToken();
if (cmd == "help") {
helpCommand();
}
else if (cmd == "enqueue") {
if(scanner.hasMoreTokens()){
string value=scanner.nextToken();
if(scanner.hasMoreTokens()){
scanner.scanNumbers();
string priorityStr=scanner.nextToken();
double priority=stringToDouble(priorityStr);
pq.enqueue(value,priority);
}
else
pq.enqueue(value);
}
}
else if (cmd == "dequeue") {
if(pq.isEmpty())
cout<<"The queue is empty"<<endl;
else
cout<<pq.dequeue()<<endl;
}
else if (cmd == "peek") {
if(pq.isEmpty())
cout<<"The queue is empty"<<endl;
else
cout<<pq.peek()<<endl;
}
else if (cmd == "peekPriority"||cmd=="peekpriority") {
if(pq.isEmpty())
cout<<"The queue is empty"<<endl;
else
cout<<pq.peekPriority()<<endl;
}
else if (cmd == "clear") {
pq.clear();
}
else if (cmd == "size") {
cout<<pq.size()<<endl;
}
else if (cmd == "isEmpty"||cmd=="isempty") {
if(pq.isEmpty())
cout<<"true";
else
cout<<"false";
cout<<endl;
}
else if(cmd=="list")
list(pq);
else {
cout << "Undefined command: " << cmd << endl;
}
}
return 0;
}