stack STL 中栈的简单使用

来源:互联网 发布:unity3d 离线使用 编辑:程序博客网 时间:2024/05/17 20:30

 

#include "stdafx.h"

#include <iostream>

#include <stack>

#include "Windows.h"

using namespace std;

 

int _tmain(int argc, _TCHAR* argv[])

{

    stack<int> nMyStack;//

    int i = 0;

    cout << "入栈。。。" << endl;

    cout <<"----------------------------------------------------------------/n";

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

    {

        cout << i << "入栈/t";

        nMyStack.push(i);

        cout<< "当前栈顶元素" << nMyStack.top() << "/t元素个数" << nMyStack.size() << endl;

    }

    cout << "/n出栈。。。" << endl;

    cout << "----------------------------------------------------------------/n";

    while(!nMyStack.empty())

    {

        cout << nMyStack.top() << "出栈/t";

        nMyStack.pop();

    }

    if(nMyStack.empty())

    {

        cout<<"栈已为空!";

    }

    return 0;

}