fork download
  1. #include <queue>
  2. #include <vector>
  3. #include <functional>
  4. using namespace std;
  5.  
  6. template<typename Pair>
  7. struct GreaterBySecond {
  8. bool operator()(Pair a, Pair b) const {
  9. return a.second > b.second;
  10. }
  11. };
  12.  
  13. int main(){
  14. typedef pair<int,float> ifpair;
  15. GreaterBySecond<ifpair> comp;
  16. typedef priority_queue< ifpair , vector<ifpair>, decltype( comp ) > t_npq;
  17. t_npq npq( comp );
  18. //do something with npq. finish using it (without emptying it) and clear for next round
  19. t_npq empty( comp );
  20. swap(npq , empty);
  21. }
  22.  
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty