关于c++中的STL中的栈stack的使用
来源:互联网 发布:js链表 编辑:程序博客网 时间:2024/05/21 01:29
1.首先,STL库是c++特有的,c语言是没有的,因为c语言不支持模板和泛型,不支持类,所以只能在c++中使用STL中的栈stack。
2.先引入栈stack:
#include<stack>
3.声明和初始化一个栈:
stack<double> numbers;//这里使用了泛型,也就是c++中的类模板,不多解释!
4.进栈操作:
numbers.push(2.3456);
5.出栈操作:
numbers.pop();//栈的数据结构是last in first out(后进先出),所以就可以直接出栈numbers.pop().
6.例子:
==========使用STL中的栈进行序列的反转,请修改好下面代码中的语法错误,编译运行==========
#include <stack>
int main( )
/* Pre: The user supplies an integer n andn decimal numbers.
Post: The numbers are printed in reverseorder.
Uses: The STL class stack and its methods*/
{
int n;
double item;
stack<double> numbers; // declaresand initializes a stack of numbers
cout << " Type in an integer nfollowed by n decimal numbers."
<< endl
<< " The numbers will be printedin reverse order."
<< endl;
cin >> n;
for (int i = 0; i < n; iCC) {
cin >> item;
numbers.push(item);
}
cout << endl << endl;
while (!numbers.empty( )) {
cout << numbers.top( ) <<" ";
numbers.pop( );
}
cout << endl;
}
- 关于c++中的STL中的栈stack的使用
- c++stl中的stack
- 关于STL中的堆栈Stack
- STL中的stack的应用
- 【day0414 C++】STL stack 栈的使用
- STL 模板库中的Stack(栈)使用
- 使用Vector模拟实现STL中的stack
- STL中的Stack
- STL 栈stack的使用
- java中的Stack的使用
- STL中的queue和stack
- STL stack的使用
- 关于c++STL中的getline()函数
- 关于stl标准容器中的迭代器的使用注意事项
- STL中的stack的pop函数为什么不返回值?
- stack STL 中栈的简单使用
- java中的Stack使用
- 关于C语言中的cons的使用。
- c# 判断点是否在区域内 点在区域内 在多边形内 判断
- VS2010调用Matlab 2010 引擎的相关设置及问题( error LNK2019: unresolved external symbol _engOpen referenced in )
- CFI查询(四)
- 学习大规模高并发Web系统架构及开发推荐书籍
- Hash和Bloom Filter
- 关于c++中的STL中的栈stack的使用
- 判断一个点是否落在多边形内
- 快速排序(quick sort)
- 解决CSS背景图片闪动和重复加载的IE6BUG
- c# 共享内存使用方法
- Web.XML 配置详解
- 台积电计划提前生产20纳米芯片 争取苹果订单
- Java 可变参函数实例
- 学习