#include <queue> #include <iostream> #include <algorithm> using namespace std; struct RouteNodePath { RouteNodePath(){} RouteNodePath(int x, int y, int z, int o ): _inroadno(x),_outroadno(y),_flagstation(z),_miles(o){} inline friend operator == (const RouteNodePath &p ,const RouteNodePath &r) { return p._miles == r._miles; } inline friend operator < (const RouteNodePath &p ,const RouteNodePath &r) { return p._miles < r._miles; } int _inroadno; int _outroadno; int _flagstation; int _miles; vector<int> _path; }; int main() { /* test 1*/ // int ia[9] = ; // priority_queue<int> ipq(ia,ia+9); // cout<< "size = " << ipq.size()<<endl; // file://结果: // file://size = 9 // // for(int i =0 ; i <= ipq.size() ;++i) // cout<<ipq.top()<<' '; // cout<<endl; // file://结果: // file://634 634 634 634 634 634 634 634 634 634 // // while(!ipq.empty()) // { // cout<<ipq.top()<<' '; // ipq.pop(); // } // file://结果 // file://634 64 64 63 23 6 5 0 0 // // cout<<endl; /* test 2 */ priority_queue<RouteNodePath> rnodepath; rnodepath.push(RouteNodePath(1,2,3,440)); rnodepath.push(RouteNodePath(2,3,1,810)); rnodepath.push(RouteNodePath(3,4,3,1040)); rnodepath.push(RouteNodePath(5,1,3,1440)); rnodepath.push(RouteNodePath(2,3,3,240)); RouteNodePath aa = rnodepath.top(); cout<<aa._miles<<endl;
/* test 3 */ priority_queue<RouteNodePath> rnodepath2; const RouteNodePath *rnodepathpt = &(rnodepath.top()); rnodepath2.push(*rnodepathpt); RouteNodePath bb = rnodepath.top(); cout<<bb._miles<<endl; RouteNodePath cc = rnodepath2.top(); cout<<cc._miles<<endl; /* test4 */ }
|