#include#include using namespace std; int main() { priority_queue pq; pq.push(5); pq.push(1); pq.push(8); while (!pq.empty()) { cout << pq.top() << " "; pq.pop(); } return 0; }
#includeThis code creates a priority_queue of customer structs and defines the '<' operator to compare the priority of the customers. It then pushes 3 customers onto the priority_queue and prints out their names in order of highest priority. The package library for using the priority_queue container in C++ STL is#include using namespace std; struct customer { string name; int priority; }; bool operator<(const customer& lhs, const customer& rhs) { return lhs.priority < rhs.priority; } int main() { priority_queue pq; pq.push({"John", 2}); pq.push({"Mary", 1}); pq.push({"Bob", 3}); while (!pq.empty()) { cout << pq.top().name << " "; pq.pop(); } return 0; }