栈的应用

· · 算法·理论

栈的应用

#include<bits/stdc++.h>
using namespace std;
stack<int>st;//定义一个栈st 
int n;
int main() {
    cin>>n;
    st.push(n);//插入n 
    int y=st.top();//将栈顶n的值赋给y 
    cout<<y;
    st.pop();//弹出栈顶n 
    cout<<st.empty();//判断st栈是否为空,空则输出0 
    cout<<st.size();//返回st栈内数的个数 
    return 0;
}