C++中自带的栈

C++中栈的用法

c++栈的方法的基本用法:
push(): 向栈内压入一个成员;
pop(): 从栈顶弹出一个成员;
empty(): 如果栈为空返回true,否则返回false;
top(): 返回栈顶,但不删除成员;
size(): 返回栈内元素的大小;

#include<iostream>
#include<stack>
using namespace std;
int main(){
	stack <int> stk;
	for(int i=0;i<10;i++){
		stk.push(i);
	}
	cout<<stk.size()<<endl;
	cout<<stk.top()<<endl;
	stk.pop();
	cout<<stk.empty()<<endl;
}

详细链接

  • https://blog.csdn.net/qq_20366761/article/details/70053813
发布了558 篇原创文章 · 获赞 295 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/zhoutianzi12/article/details/105176730