stack容器
 
常用接口
 
 
代码工程
 
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stack>
using namespace std;
void test01()
{
	stack<int>s;
	
	s.push(10);
	s.push(20);
	s.push(30);
	s.push(40);
	if (0 != s.empty())
	{
		cout << "容器为空!" << endl;
	}
	else
	{
		
		cout << "栈顶元素:" << s.top() << endl;
		
		s.pop();
		cout << "出栈后的栈顶元素:" << s.top() << endl;
	}
	cout << "栈的大小: " << s.size() << endl;
	
	while (!s.empty())
	{
		cout << s.top() << endl;
		s.pop();
	}
	cout << "栈的大小: " << s.size() << endl;
	return;
}
int main()
{
	test01();
	return 0;
}
 
运行结果
 
