stack(STL)

//Stack STL
//在STL中,栈是以别的容器作为底部结构,再将
//接口改变,使之符合栈的特性
//一共5个常用操作函数

//构造析构
stack<Elem>c;     //build a empty stack
stack<Elem>c1(c2);   //copy a stack

//5 functions
c.top();      //return the element  at the top of the stack
c.push(elem);     //push element at the top
c.pop();     //pop element at the top

c.empty();
c.size();    //return the size of the stack

//Stack is just a encapsulation of other container.
//It just supply its own interfaces.
//Elements are pushed/popped from the "back" of the specific container, which is //known as the top of the stack.

  

时间: 2024-08-26 04:04:28

stack(STL)的相关文章

数据结构---栈(STL)

codevs1051接龙游戏 第一次用STL写了写“栈” 表示还需要再多看看理解理解. 1 #include<iostream> 2 #include<stack>//STL栈 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int main() 7 { 8 string A[100005];//二维 9 int n; 10 cin>>n; 11 for(int

C++11新特性应用--介绍几个新增的便利算法(stl中的heap使用,最大堆)

有的时候为了维护数据,我们使用stl的堆去维护一序列. 首先您要弄清楚堆和栈的区别,即heap和stack stl中的堆默认是最大堆. 先介绍 push_heap,pop_heap,make_heap,sort_heap这四个算法,这四个不是C++11新增加的内容. 首先是如何产生一个最大推: make_heap 原型: template <class RandomAccessIterator> void make_heap (RandomAccessIterator first, Rando

用STL设计消息队列、优先级消息队列、资源分配管理器

STL库老早已经成为C++的一部分,在使用C++开发项目的过程中,很多人还在犹豫要不要使用STL库,觉得STL库很难,其实不然.我工作的项目中现在大量使用STL库,STL使用调试简单,高效,可以减少很多重复的代码. 本文的主要目的是使用STL的queue 和 priority queue来阐述下项目中经常使用的消息队列以及资源分配模式.本文的例子主要如下: 消息队列 带优先级的消息队列 资源分配管理器 STL容器 我们将使用下面的容器来实现本文的例子: queue 队列容器支持添加一个元素,并且

C语音常用库和函数

#include <assert.h> //设定插入点 #include <ctype.h> //字符处理 #include <errno.h> //定义错误码 #include <float.h> //浮点数处理 #include <fstream.h> //文件输入/输出 #include <iomanip.h> //参数化输入/输出 #include <iostream.h> //数据流输入/输出 #include

C/C++头文件一览

C/C++头文件一览 C.传统 C++#include <assert.h> //设定插入点#include <ctype.h> //字符处理#include <errno.h> //定义错误码#include <float.h> //浮点数处理#include <fstream.h> //文件输入/输出#include <iomanip.h> //参数化输入/输出#include <iostream.h> //数据流输入

C++常用库函数

C++常用库函数  转自:http://blog.csdn.net/sai19841003/article/details/7957115 1.常用数学函数 头文件 #include <math> 或者 #include <math.h>   函数原型 功能 返回值 int abs(int x) 求整数x的绝对值 绝对值 double acos(double x) 计算arcos(x)的值 计算结果 double asin(double x) 计算arsin(x)的值 计算结果 d

linux常用头文件详解

POSIX标准定义的头文件 <dirent.h>        目录项 <fcntl.h>         文件控制 <fnmatch.h>    文件名匹配类型 <glob.h>    路径名模式匹配类型 <grp.h>        组文件 <netdb.h>    网络数据库操作 <pwd.h>        口令文件 <regex.h>    正则表达式 <tar.h>        TAR

C C++每个头文件的功能说

C/C++每个头文件的功能说明 传统 C++ #include <assert.h> //设定插入点 #include <ctype.h> //字符处理 #include <errno.h> //定义错误码 #include <float.h> //浮点数处理 #include <fstream.h> //文件输入/输出 #include <iomanip.h> //参数化输入/输出 #include <iostream.h&g

C++库函数大全

C++常用库函数   1.常用数学函数 头文件 #include <math> 或者 #include <math.h>   函数原型 功能 返回值 int abs(int x) 求整数x的绝对值 绝对值 double acos(double x) 计算arcos(x)的值 计算结果 double asin(double x) 计算arsin(x)的值 计算结果 double atan(double x) 计算arctan(x)的值 计算结果 double cos(double x