当前位置: 首页>>代码示例>>C++>>正文


C++ PriorityQueue::peek方法代码示例

本文整理汇总了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;
}
开发者ID:johan-bjareholt,项目名称:cpp-playground,代码行数:28,代码来源:main.cpp

示例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;
}
开发者ID:jwhurt,项目名称:Projects,代码行数:67,代码来源:PQTest.cpp


注:本文中的PriorityQueue::peek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。