zoukankan      html  css  js  c++  java
  • 优先队列(priority_queue)自定义排序方法

    #include<iostream>
    #include<vector>
    #include<queue>
    using namespace std;
    struct cmp{
    	 
    	    bool  operator ()  ( int  r , int  l  ){
    	   	      return r > l;
    	   } 
    }; 
    struct cmp1{
    	   bool operator ()( int a ,int b ){
    	   	   return a<b;
    	   }
    };
    int  main(void){
    	 
    	
    	 //   priority_queue< int > q;// 默认是 从大到小。 
    	 //   priority_queue < int , vector<int> ,less<int> > q;//从大到小 
    	 //   priority_queue < int , vector<int>, greater<int> > q; //从小到大
    	 //  priority_queue < int , vector<int> , cmp1  > q;//从大到小
    	 //   priority_queue < int , vector<int> , cmp  > q;//从小到大
    	 q.push( 1 );
    	 q.push( 2 );
    	 q.push( 3 );
    	 
    	 while( !q.empty() ){
    	      int t =q.top();
    	     q.pop();
    	     printf("%d ",t);
    	  
    	 } 
    	  return 0;
    }
    
  • 相关阅读:
    Maria 与Ann的故事
    引语
    Preface
    Chapter 1 Foundation
    Roman to Integer
    Integer to Roman
    Container with most water
    palindrome number
    String to Integer (atoi)
    Reverse Integer
  • 原文地址:https://www.cnblogs.com/eason9906/p/11754731.html
Copyright © 2011-2022 走看看