#include <iostream>
#include <stack>
//stack 不遍历 不支持随机访问 必须pop出去 才能进行访问
using namespace std; void test01() {
//初始化
stack<int> s1;
stack<int> s2(s1);
//stack操作
//首先是压栈
s1.push();
s1.push();
s1.push();
//返回栈顶元素
cout << "栈顶元素为 " << s1.top() << endl;
//出栈
s1.pop(); //打印 不能遍历 cout top后只能pop掉 打印下一个元素
while (!s1.empty()) {
cout << s1.top() << endl;
s1.pop();
} //size()
cout <<"size: "<< s1.size() << endl; //栈容器存放对象指针 自练
//栈容器存放对象
}
int main() { }
相关文章
- 5.Min Stack(能返回最小数的栈)
- STL-stack栈容器&queue队列容器
- C++ STL 学习笔记__(5)list
- STL - stack(栈)
- STL笔记(5)条款49:学习破解有关STL的编译器诊断信息
- 小白的CTF学习之路5——内存的逻辑结构
- STL学习笔记5--map and multimap
- C++学习总结(二十七)——STL容器与算法(一) STL容器的组成,线性容器(array,vector,tuple,queue,deque,stack),链式容器(list)
- STL概览——栈( stack )、队列( queue )和优先级队列( priority_queue)
- 标准模板库(STL)学习探究之stack