stl源码剖析 详细学习笔记stack queue
//
// stack.cpp
// 笔记
//
// Created by fam on 15/3/15.
//
//
//---------------------------15/03/15----------------------------
//stack
{
/*
stack概述:
stack只采用deque的底部操作,封装了deque,形成stack
这种方式是常见的adapter设计模式,stack往往不被归类为container
而是被归类为 container adapter
*/
template <class T,
class Sequence = deque<T> >
class stack
{
friend bool
operator== __STL_NULL_TMPL_ARGS (const stack&,
const stack&);
friend bool
operator< __STL_NULL_TMPL_ARGS (const stack&,
const stack&);
public:
typedef typename Sequence::value_type value_type;
typedef typename Sequence::size_type size_type;
typedef typename Sequence::reference reference;
typedef typename Sequence::const_reference const_reference;
protected:
Sequence c;
public:
bool empty() const{
return c.empty();}
size_type size()
const {return c.size();}
reference top() {return c.back();}
const_reference top()
const {return c.back();}
void push(const value_type& x) {c.push_back(x);}
void pop() {c.pop_back();}
};
template<class T,
class Sequence>
bool operator==(const stack<T,Sequence>& x,
const stack<T, Sequence>& y)
{
return x.c == y.c;
}
template<class T,
class Sequence>
bool operator<(const stack<T,Sequence>& x,
const stack<T, Sequence>& y)
{
return x.c<y.c;
}
//stack没有迭代器,所有的元素都必须符合先进后出的条件,所以不提供访问其他元素的迭代器
}
//queue
{
//queue
先进后出 可以用deque作为底层结构
template <class T,
class Sequence = deque<T> >
class queue
{
friend bool
operator== __STL_NULL_TMPL_ARGS (const stack&,
const stack&);
friend bool
operator< __STL_NULL_TMPL_ARGS (const stack&,
const stack&);
public:
typedef typename Sequence::value_type value_type;
typedef typename Sequence::size_type size_type;
typedef typename Sequence::reference reference;
typedef typename Sequence::const_reference const_reference;
protected:
Sequence c;
public:
bool empty() const{
return c.empty();}
size_type size()
const {return c.size();}
reference front() {return c.front();}
const_reference front()
const {return c.front();}
reference back(){return c.back();}
const_reference back()
const {return c.back();}
void push(const value_type& x){c.push_back(x);}
void pop() {c.pop_front();}
};
template<class T,
class Sequence>
bool operator==(const stack<T,Sequence>& x,
const stack<T, Sequence>& y)
{
return x.c == y.c;
}
template<class T,
class Sequence>
bool operator<(const stack<T,Sequence>& x,
const stack<T, Sequence>& y)
{
return x.c<y.c;
}
//queue也没有迭代器
//总结:
这两个数据结构毫无难度
}
stl源码剖析 详细学习笔记stack queue的更多相关文章
- stl源码剖析 详细学习笔记 hashtable
//---------------------------15/03/24---------------------------- //hashtable { /* 概述: sgi采用的是开链法完成h ...
- stl源码剖析 详细学习笔记 set map
// // set map.cpp // 笔记 // // Created by fam on 15/3/23. // // //---------------------------15/03 ...
- stl源码剖析 详细学习笔记 RB_tree (1)
// // RB_tree_STL.cpp // 笔记 // // Created by fam on 15/3/21. // // #include "RB_tree_STL.h&q ...
- stl源码剖析 详细学习笔记heap
// // heap.cpp // 笔记 // // Created by fam on 15/3/15. // // //---------------------------15/03/15 ...
- stl源码剖析 详细学习笔记 空间配置器
//---------------------------15/04/05---------------------------- /* 空间配置器概述: 1:new操作包含两个阶段操作 1>调 ...
- stl源码剖析 详细学习笔记 配接器
//---------------------------15/04/03---------------------------- /* 配接器概述: 1:adapter是一种设计模式:将一个clas ...
- stl源码剖析 详细学习笔记 算法(1)
//---------------------------15/03/27---------------------------- //算法 { /* 质变算法:会改变操作对象之值 所有的stl算法都 ...
- stl源码剖析 详细学习笔记 算法总览
//****************************基本算法***************************** /* stl算法总览,不在stl标准规格的sgi专属算法,都以 *加以标 ...
- stl源码剖析 详细学习笔记 RB_tree (2)
//---------------------------15/03/22---------------------------- //一直好奇KeyOfValue是什么,查了下就是一个和仿函数差不多 ...
随机推荐
- win10 安装microsoft.net framework3.5
转载于:https://www.windows10.pro/win10-net-framework-3-5/ 之前手残不小心把microsoft.net framework3.5删了,结果导致Sql ...
- Oracle 与 mysql 建立透明网关
1.1.1. 文档编写目的 项目上需要做与Mysql数据库的对接,然而Oracle与Mysql数据库是异构的,因此这里采用透明网关的方式来解决. 另,项目上的环境为APP:12.2.6 ; DB: ...
- zabbix待完整
fad 下载zabbix3.4的配置文件 wget -O zabbix-3.4.2.tar.gz http://sourceforge.net/projects/zabbix/files/ZABBIX ...
- iptables实战演练
iptables禁止 ip 10.10.10.1 访问本地80端口: iptables -t filter -I INPUT -s 10.10.10.1 -p tcp –dport 80 -j DRO ...
- Q矩阵输出
程序启动时: 1.Q矩阵在InitQX中对角阵赋初值为0.25,GPS卫星数6 2.Q矩阵初值在初始化时由GetBL获得,改变Q对角阵 Q初值第0个卫星 10000000000.000 X初值第0个卫 ...
- 【优质】React的学习资源
React的学习资源 github 地址: https://github.com/LeuisKen/react-collection https://github.com/reactnativecn/ ...
- codeforces 671D Roads in Yusland & hdu 5293 Tree chain problem
dp dp优化 dfs序 线段树 算是一个套路.可以处理在树上取链的问题.
- 团队作业——Alpha冲刺 12/12
团队作业--Alpha冲刺 冲刺任务安排 杨光海天 今日任务:自定义保存界面布局以及交互接口函数的实现 明日任务:总结项目中的问题,为什么没能按照预期推进项目 郭剑南 今日任务:继续解决Python编 ...
- 洛谷 P4707 【重返现世】
题目分析 题目就是求第K种原料的出现期望时间. 考虑广义min-max容斥. \(\text{kthmax}(S)=\sum\limits_{T\subseteq S}(-1)^{|T|-k}\bin ...
- python第二十六课——装饰器
装饰器是闭包的一种使用场景: python中的装饰器在定义上需要传入一个函数对象, 在此函数执行之前或者之后都可以追加其它的操作, 这样做的好处是,在不改变源码(原本业务逻辑的)同时,进行功能的扩展: ...