stack容器

1.1stack基本概念

C++编程入门之十一(stack容器)
入栈叫push,出栈叫pop
C++编程入门之十一(stack容器)

1.1stack常用接口

C++编程入门之十一(stack容器)

#include"pch.h"
#include<iostream>
#include<string>
#include<opencv2/opencv.hpp>
#include<vector>
#include<algorithm> // 标准算法头文件
#include<stack>        
        
using namespace std;
using namespace cv;

//栈stack容器
void test01()
{
	stack<int>s;
	s.push(10);
	s.push(20);
	s.push(30);
	s.push(40);
	cout << "栈的大小:" << s.size() << endl;
	while (!s.empty())
	{
		cout << "栈顶元素为:" << s.top() << endl; 
		s.pop();
	}
	cout << "栈的大小:" << s.size() << endl;
}

int main()
{
	test01();
	system("pause");
	return 0;
}

相关文章:

  • 2021-07-29
  • 2022-12-23
  • 2021-06-23
  • 2021-10-02
  • 2021-12-10
  • 2022-01-21
  • 2022-12-23
  • 2021-10-19
猜你喜欢
  • 2022-01-04
  • 2021-07-16
  • 2022-12-23
  • 2021-12-02
  • 2021-07-13
  • 2021-08-13
  • 2021-10-09
相关资源
相似解决方案