c++ stl栈stack使用
来源:互联网 发布:切片软件哪个好 编辑:程序博客网 时间:2024/05/22 15:00
c++ stl栈stack使用
C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构。
c++ stl栈stack的头文件为:
#include <stack>
c++ stl栈stack的成员函数介绍
操作 比较和分配堆栈
empty() 堆栈为空则返回真
pop() 移除栈顶元素
push() 在栈顶增加元素
size() 返回栈中元素数目
top() 返回栈顶元素
c++ stl栈stack用法代码举例1
#include "stdafx.h" #include <stack> #include <vector> #include <deque> #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { deque<int> mydeque(2,100); vector<int> myvector(2,200); stack<int> first; stack<int> second(mydeque); stack<int,vector<int> > third; stack<int,vector<int> > fourth(myvector); cout << "size of first: " << (int) first.size() << endl; cout << "size of second: " << (int) second.size() << endl; cout << "size of third: " << (int) third.size() << endl; cout << "size of fourth: " << (int) fourth.size() << endl; return 0; }
c++ stl栈stack用法代码举例2
// stack::empty #include <iostream> #include <stack> using namespace std; int main () { stack<int> mystack; int sum (0); for (int i=1;i<=10;i++) mystack.push(i); while (!mystack.empty()) { sum += mystack.top(); mystack.pop(); } cout << "total: " << sum << endl; return 0; }
c++ stl栈stack用法代码举例3
// stack::push/pop #include <iostream> #include <stack> using namespace std; int main () { stack<int> mystack; for (int i=0; i<5; ++i) mystack.push(i); cout << "Popping out elements..."; while (!mystack.empty()) { cout << " " << mystack.top(); mystack.pop(); } cout << endl; return 0; }
c++ stl栈stack用法代码举例4
#include <iostream> #include <stack> using namespace std; int main () { stack<int> mystack; for (int i=0; i<5; ++i) mystack.push(i); cout << "Popping out elements..."; while (!mystack.empty()) { cout << " " << mystack.top(); mystack.pop(); } cout << endl; return 0; }
0 0
- 【day0414 C++】STL stack 栈的使用
- c++ stl栈stack使用
- STL 栈stack的使用
- c++stl中的stack
- stack STL 中栈的简单使用
- stl stack使用...
- STL stack简单使用
- STL stack的使用
- STL stack栈
- STL-栈stack
- STL之stack(栈)
- STL:栈(stack)
- STL - stack(栈)
- C++ STL stack栈
- STL容器stack栈
- STL-stack(栈)
- STL-stack实现栈
- 【STL】栈适配器stack
- php请求接口
- 【OpenCV学习笔记 017】图像颜色分布直方图
- 关于apk 反编译的使用和注意事项
- ubuntu14.04+cuda8.0+cudnn5.1+caffe+tensorflow 安装教程(三)
- UTF-8 可变编码格式
- c++ stl栈stack使用
- 数据存储——数据库_开源数据库LitePal
- 内存字节对齐
- 延迟加载
- 播放快捷键和service使用
- 移动端时间选择器(更新1.2.0版本)
- JAVA:正则表达式(代码说话)
- 关于CSDN markdown 编辑器命令的一些记录
- Android应用内消息计数(角标)模型及解决方案