/* This is a free program, you can modify or redistribute it under the terms of GNU * Description: Example of priority queue usage * language: C ++ * Development Environment: vc6.0 * Author: wangzhicheng * E-mail: 2363702560@qq.com * Date: 2012/10/18 * // * priority_queue priority queue is a one-way queue of the concept of ownership value, in this queue, all elements are sorted by priority. In the specific implementation of STL, priority_queue also uses another container as the bottom structure, then adjust the positions between elements according to the heap processing rules */# include <iostream> # include <queue> # include <string> using namespace STD; const int max = 1000; class person {PRIVATE: int nice; // priority string name; public: Person (INT nice = 0, string name = "") {This-> nice = nice; this-> name = Name;} person (const person & P) {nice = P. nice; name = P. name;} person & operator = (const person & P) {nice = P. nice; name = P. name; return * This;} fr Iend bool operator <(const person & P1, const person & p2) {If (p1.getnice ()! = Maid () {return p1.getnice () <p2.getnice ();} return p1.getname () <p2.getname ();} void setnice (INT nice) {This-> nice = nice;} int getnice () const {return nice;} void setname (string name) {This-> name = Name;} string getname () const {return name;} friend istream & operator> (istream & is, person & P) {int nice; string name; cout <"Enter personnel priority :"; cin> nice; If (! Cin. Good () {cerr <"input error! "<Endl; is. Clear (); return is ;}if (Nice <0 | nice >=max) {cerr <" the input range is incorrect! "<Endl; is. clear (); return is ;}cout <"Enter the person's name:"; CIN >>> name; p. setnice (NICE); p. setname (name); return is;} friend ostream & operator <(ostream & OS, person & P) {OS <"name:" <p. getname () <Endl; OS <"Priority:" <p. getnice () <Endl; return OS ;}}; class lessthan {public: bool operator () (const person & P1, const person & p2) {If (p1.getnice ()! = P2.getnice () {return p1.getnice () <p2.getnice ();} return p1.getname () <p2.getname () ;}}; const int N = 4; void main () {int nice; string name; int I; person P; priority_queue <person, vector <person> q; for (I = 0; I <n; I ++) {cout <"Enter the" <I <"personnel information" <Endl; CIN> P; q. push (p);} while (Q. empty () = false) {cout <q. top (); q. pop ();}}