您的位置:首页 > 其它

STL容器使用DEMO-stack

2009-08-24 16:33 344 查看
Code:

//////////////////////////////////////////////////////////////////////////

// CopyRight(c) 2009, YOYO, All Rights Reserved.

// Author: LIN YiQian

// Created: 2009/08/24

// Describe: STL stack 使用DEMO

//////////////////////////////////////////////////////////////////////////

#include <iostream>

#include <stack>



using namespace std;



typedef stack<int> INT_STK;



void main(void)

{

INT_STK stkInt;



// Print is stack empty?

cout << "Stack Empty?: " << boolalpha << stkInt.empty() << endl;



// Push elements

for (int i = 0; i < 10; i += 2)

{

stkInt.push(i);

}



// Get size

cout << "Stack size: " << stkInt.size() << endl;



// Get top element & change its value

if (!stkInt.empty())

{

cout << "Top Element: " << stkInt.top() << " change to 99 " << endl;

stkInt.top() = 99;

}



// Print stack

{

while (!stkInt.empty())

{

cout << stkInt.top() << " ";

stkInt.pop();

}

}

cout << endl;



system("pause");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: