【C++】解析stack和queue底层数据结构 - - - - deque

1. stack和queue源码

  • 由stack和queue源码可知,其实stack和queue是将deque容器进行再封装,其底层是一个deque容器
  • 对stack和queue操作,其实间接操作的是deque容器

stack源码

template<class _Ty, class _Container = deque<_Ty> > // deque容器
class stack
{
   
      // LIFO queue implemented with a container
protected:
    _Container c;   // the underlying container
public:
    // test if stack is empty
    bool empty() const {
   
    return (c.empty()); }

    // test length of stack
    size_type size() const {
   
    return (c.size()); }

    // return last element of mutable stack
    reference top() {
   
    return (c.back()); }

    // return last element of nonmutable stack
    const_reference top() const {
   
    return (c.back()); }

    // insert element at end
    void push(const value_type& _Val) {
   
    c
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值