Datová struktura “priority_queue”

{“https:\/\/www.jdoodle.com\/a\/cBV?format=text”:”#include <iostream>\n#include <queue>\nusing namespace std;\n\nconst int itemCount = 10;\nint data[itemCount] = { 1, 4, 3, 5, 2, 4, 6, 3, 7, 1 };\n\nint main() {\n priority_queue<int> pq;\n for(int i = 0; i < itemCount; i++)\n pq.push(data[i]);\n \n while(! pq.empty()) {\n cout << pq.top() << ";";\n pq.pop();\n }\n return 0;\n}”,”https:\/\/www.jdoodle.com\/a\/cBX?format=text”:”#include <iostream>\n#include <queue>\n#include <string>\nusing namespace std;\n\nstruct Employee {\n string name;\n int wage;\n \n Employee(string n, int w): name(n), wage(w) {}\n \n bool operator<(const Employee& emp) const {\n return wage < emp.wage;\n }\n};\n\nostream& operator<<(ostream& os, const Employee& emp) {\n os << emp.name << ": " << emp.wage << " K\u010d" << endl;\n return os;\n}\n\nint main() {\n priority_queue<Employee> empPQ;\n empPQ.emplace("Ale\u0161", 20000);\n empPQ.emplace("Monika", 30000);\n empPQ.emplace("Yveta", 15000);\n empPQ.emplace("V\u00e1clav", 40000);\n empPQ.emplace("Dominik", 25000);\n \n while(! empPQ.empty()) {\n cout << empPQ.top();\n empPQ.pop();\n }\n}”}


Datová struktura “priority_queue”
Ohodnoťte tento článek