C++中STL-stack的用法

栈先进后出

s.push()入栈

s.pop()出栈即弹出栈顶元素

s.top()返回栈顶元素

s.size()返回栈中元素的个数

#include<stdio.h>
#include<algorithm>
using namespace std;
#include<stack>
int main()
{
	int count;
	stack<int>s;
	s.push(8);
	s.push(9);
	count=s.size();
	printf("%d\n",count);
	while(!s.empty())
	{
		printf("%d\n",s.top());
		s.pop();
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/hezhiying_/article/details/81118314
今日推荐