STL stack堆栈容器
来源:互联网 发布:阿利伯克级驱逐舰数据 编辑:程序博客网 时间:2024/04/30 18:01
stack堆栈容器
【stack的定义】
stack的声明:#include<stack>
定义:stack<int>s;
【stack的性质】
stack堆栈是一个后进先出的线性表,插入和删除都只能在表的一端进行,插入元素叫入栈,删除元素叫 出栈。
【stack的函数】
stack<int>s;
1. s.push(x) 将元素x入栈
2. s.pop() 删除栈顶元素
3. s.top() 读取栈顶元素
4. s.empty() 判断堆栈是否为空
【stack的基本操作】
#include<stack>#include<iostream>using namespace std;int main(){ stack<int>s; // push()将从栈顶元素入栈,stack不能从栈尾入栈 s.push(1); s.push(2); s.push(3); s.push(9); // top()访问栈顶元素 cout<<s.top()<<endl; // size()堆栈元素数量 cout<<s.size()<<endl; // empty()判断堆栈是否为空 cout<<s.empty()<<endl; while(!s.empty()) <span style="color:#ff0000;">// 经常用到的代码</span> { cout<<s.top()<<" "; // pop()栈顶出栈 s.pop(); } cout<<endl; return 0;}
0 0
- STL stack堆栈容器
- C++ STL--stack堆栈容器学习笔记
- STL(十八)stack堆栈容器
- STL序列式容器之堆栈——stack
- stack堆栈容器
- stack堆栈容器
- stack堆栈容器
- stack堆栈容器
- STL容器适配器:stack
- STL容器之stack
- STL容器之stack
- STL stack容器
- stl之stack容器
- STL容器stack栈
- stl::stack容器学习
- STL容器之stack
- STL之stack容器
- STL-stack容器
- Winform文件下载之WinINet
- iOS开发多线程篇—线程安全
- 一般权限管理系统构思及设计
- 使用JDBC操作数据库(mysql):
- django环境配置
- STL stack堆栈容器
- ubuntu livecd isolinux的定制
- 基于 Linux 的服务端环境自动部署
- NETTY之FUTURE和CHANNELFUTURE
- Metastore contains multiple versions
- 机器学习——随机森林算法及原理
- activemq
- 在Java里处理文件的技巧
- c#泛型使用详解:泛型特点、泛型继承、泛型接口、泛型委托