c++ stl栈容器stack的pop(),push()等用法介绍及头文件
来源:互联网 发布:android快递查询源码 编辑:程序博客网 时间:2024/06/08 07:33
c++ stl栈stack介绍C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构。c++ stl栈stack的头文件为:#include <stack>c++ stl栈stack的成员函数介绍操作 ...
c++ stl栈stack介绍
C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构。
c++ stl栈stack的头文件为:
#include <stack>
c++ stl栈stack的成员函数介绍
操作 比较和分配堆栈
empty() 堆栈为空则返回真
pop() 移除栈顶元素
push() 在栈顶增加元素
size() 返回栈中元素数目
top() 返回栈顶元素
c++ stl栈stack用法代码举例1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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
- c++ stl栈容器stack的pop(),push()等用法介绍及头文件
- c++ stl栈容器stack的pop(),push()等用法介绍及头文件
- c++ stl栈容器stack的pop(),push()等用法介绍及头文件
- c++ stl栈容器stack的pop(),push()等用法介绍及头文件
- c++ stl栈容器stack的pop(),push()等函数用法介绍及头文件
- c++ stl栈容器stack的pop(),push()等用法介绍
- c++ stl容器vector删除(erase),遍历等基本用法介绍及头文件
- c++ stl容器vector删除(erase),遍历等基本用法介绍及头文件
- c++ stl容器vector删除(erase),遍历等基本用法介绍及头文件
- c++stack容器介绍
- c++stack容器介绍
- c++stack容器介绍
- c++stack容器介绍
- c++stack容器介绍
- c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例
- c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例
- STL容器stack栈
- STL stack pop函数
- ThinkPad T450无线网络不可用解决笔记
- PL/SQL如何调试Oracle存储过程
- 动态数据源3之动态分库反思
- Hadoop集群之Hive安装配置
- spring boot实战一
- c++ stl栈容器stack的pop(),push()等用法介绍及头文件
- ubuntu安装sbt
- mysql主从复制
- dom4j在指定位置添加标签更新标签
- C_C++变量命名规则
- 玩转Android之Picasso使用详详详详详详解,从入门到源码剖析!!!!
- 注入攻击--SQL注入
- HDU 2222 板子题
- UFONet —— 一款开放的DDoS重定向攻击工具