跳到正文

算法·理论

栈的应用

Pazy约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年8月23日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 1 分钟

版本

  1. v1当前

栈的应用

C++
#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;
}
原文