STL容器使用DEMO-stack

Code:
  1. //   
  2. //  CopyRight(c) 2009, YOYO, All Rights Reserved.   
  3. //  Author: LIN YiQian   
  4. //  Created: 2009/08/24   
  5. //  Describe: STL stack 使用DEMO   
  6. //   
  7. #include <iostream>   
  8. #include <stack>   
  9.   
  10. using namespace std;   
  11.   
  12. typedef stack<int> INT_STK;   
  13.   
  14. void main(void)   
  15. {   
  16.     INT_STK stkInt;   
  17.   
  18.     //  Print is stack empty?   
  19.     cout << "Stack Empty?: " << boolalpha << stkInt.empty() << endl;   
  20.   
  21.     //  Push elements   
  22.     for (int i = 0; i < 10; i += 2)   
  23.     {   
  24.         stkInt.push(i);   
  25.     }   
  26.   
  27.     //  Get size   
  28.     cout << "Stack size: " << stkInt.size() << endl;   
  29.   
  30.     //  Get top element & change its value   
  31.     if (!stkInt.empty())   
  32.     {   
  33.         cout << "Top Element: " << stkInt.top() << " change to 99 " << endl;   
  34.         stkInt.top() = 99;   
  35.     }   
  36.   
  37.     //  Print stack   
  38.     {   
  39.         while (!stkInt.empty())   
  40.         {   
  41.             cout << stkInt.top() << " ";   
  42.             stkInt.pop();   
  43.         }   
  44.     }   
  45.     cout << endl;   
  46.   
  47.     system("pause");   
  48. }  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值