小试 priority_queue

发表于:2007-05-25来源:作者:点击数: 标签:小试priorityqueueque#include
#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 ==

#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 */
 
 

 
  
 
}


原文转自:http://www.ltesting.net

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)