STL容器使用DEMO-queue

Code:
  1. //   
  2. //  CopyRight(c) 2009, YOYO, All Rights Reserved.   
  3. //  Author: LIN YiQian   
  4. //  Created: 2009/08/24   
  5. //  Describe: STL queue 使用DEMO   
  6. //   
  7. #include <iostream>   
  8. #include <queue>   
  9.   
  10. using namespace std;   
  11.   
  12. typedef queue<int> INT_QUE;   
  13.   
  14. void main(void)   
  15. {   
  16.     INT_QUE intQue;   
  17.     int x;   
  18.   
  19.     //  Push   
  20.     cout << "Please input some Non-negative integer(put negative integer to finish input): " << endl;   
  21.     while (cin>>x)   
  22.     {   
  23.         if (x<0) break;   
  24.         intQue.push(x);   
  25.     }   
  26.   
  27.     //  Size   
  28.     cout << "Queue Size: " << intQue.size() << endl;   
  29.   
  30.     //  Empty?   
  31.     cout << "Queue Empty?: " << boolalpha << intQue.empty() << endl;   
  32.   
  33.     //  Change Front Element & Back Element   
  34.     {   
  35.         cout << "Queue front Element: " << intQue.front() << " Change to 99" << endl;   
  36.         intQue.front() = 99;   
  37.   
  38.         cout << "Queue back Element: " << intQue.back() << " Change to 33" << endl;   
  39.         intQue.back() = 33;   
  40.     }   
  41.   
  42.     //  Print Queue   
  43.     {   
  44.         cout << "Queue: ";   
  45.         while (!intQue.empty())   
  46.         {   
  47.             cout << intQue.front() << " ";   
  48.             intQue.pop();   
  49.         }   
  50.         cout << endl;   
  51.     }   
  52.   
  53.     system("pause");   
  54. }  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值