a default max priority queue of kids and a customized min priority queue of kids


👍 g++ -std=c++11 stl_pq_kids_r.cpp
👍 ./a.out
pqName1:(Ryan,11) (Peter,14) (Felix,12) 
pqName2:(Felix,12) (Peter,14) (Ryan,11)

👍 cat stl_pq_kids_r.cpp
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct Kid {
  string name;
  int age;
  bool operator<(const Kid &k) const
    { return name < k.name; }
  bool operator==(const Kid &k) const{ 
    return name == k.name && 
           age  == k.age; }
  bool operator>(const Kid &k) const { 
    return !(*this == k) && 
           !(*this < k); }
};

ostream& operator<<(ostream &o,
                    const Kid &k){
  o << "(" << k.name << ","
    << k.age << ")";
  return o;
}

template<class A, class B, class C>
void prt(string msg,
         priority_queue<A,B,C> q) {
  cout << msg;
  while (!q.empty()) {
    cout << q.top() << ' ';
    q.pop();
  }
  cout << endl;
}

int main() {
  Kid kids[]{Kid{"Felix", 12},
             Kid{"Peter", 14},
             Kid{"Ryan",  11}};
  priority_queue<Kid> pqName1(kids, 
                              kids+3);
  prt("pqName1:", pqName1);

  priority_queue<Kid, 
                 vector<Kid>, 
                 greater<Kid>> 
    pqName2(kids, kids+3);
  prt("pqName2:", pqName2);
}


    

ch 4.6 PRIORITY QUEUES IN THE STANDARD TEMPLATE LIBRARY p153 of

ch 1.8 VECTORS IN THE STANDARD TEMPLATE LIBRARY p34 of