#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实现输入数据的逆序输出:
#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实现输入数据的逆序输出: