C++爱好者 - 网友留言

1052阅读 0评论2008-12-17 3JTwF2T
分类:

 #include
 #include
 #include
 #include
 #include
 using namespace std;
 int main(void)
 {
   // Make a priority queue of int using a vector container
   priority_queue, less > pq;

   // Push a couple of values
   pq.push(1);
   pq.push(2);
   // Pop a couple of values and examine the ends
   cout << pq.top() << endl;
   pq.pop();
   cout << pq.top() << endl;

   pq.pop();
   // Make a priority queue of strings using
   // a deque container
   priority_queue, less >
      pqs;
   // Push on a few strings then pop them back off
   int i;
   for (i = 0; i < 10; i++)
   {
     pqs.push(string(i+1,'a'));
     cout << pqs.top() << endl;
   }
   for (i = 0; i < 10; i++)
   {
     cout << pqs.top() << endl;
     pqs.pop();
   }
   // Make a priority queue of strings using a deque    

   // container, and greater as the compare operation
   priority_queue, greater >
      pgqs;
   // Push on a few strings then pop them back off
   for (i = 0; i < 10; i++)
   {
     pgqs.push(string(i+1,'a'));
     cout << pgqs.top() << endl;
   }
   for (i = 0; i < 10; i++)
   {
     cout << pgqs.top() << endl;
     pgqs.pop();
   }
   return 0;
 }

--------------------next---------------------

上一篇:C++爱好者 - 网友留言
下一篇:C++爱好者 - 网友留言