C++ STL 一个简单的<stack>程序

#include <iostream>
#include <stack>
using namespace std;

int main()
{
    stack<int> st;
    for(int i=0;i<10;++i){
        st.push(i);
    }
    while(!st.empty()){
        cout<<st.top()<<" ";
        st.pop();  //弹出元素
    }
    return 0;
}

stack实现输入数据的逆序输出:


猜你喜欢

转载自blog.csdn.net/ibelievesunshine/article/details/80204649