stl-stack-源码-可以供学习其中的实现,魔板编程

====================================================||

欢迎讨论技术的可以相互加微信:windgs (请备注csdn+xx职业)

====================================================||

// stack standard header
#pragma once
#ifndef _STACK_
#define _STACK_
#ifndef RC_INVOKED
#include <deque>

#ifdef _MSC_VER
 #pragma pack(push,_CRT_PACKING)
 #pragma warning(push,3)
#endif  /* _MSC_VER */
_STD_BEGIN

        // TEMPLATE CLASS stack
template<class _Ty,    class _Container = deque<_Ty> >
    class stack
    {    // LIFO queue implemented with a container
public:
    typedef _Container container_type;
    typedef typename _Container::value_type value_type;
    typedef typename _Container::size_type size_type;
    typedef typename _Container::reference reference;
    typedef typename _Container::const_reference const_reference;

    stack() : c()
        {    // construct with empty container
        }

    explicit stack(const _Container& _Cont) : c(_Cont)
        {    // construct by copying specified container
        }

    bool empty() const
        {    // test if stack is empty
        return (c.empty());
        }

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

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

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

    void push(const value_type& _Val)
        {    // insert element at end
        c.push_back(_Val);
        }

    void pop()
        {    // erase last element
        c.pop_back();
        }

    const _Container& _Get_container() const
        {    // get reference to container
        return (c);
        }

protected:
    _Container c;    // the underlying container
    };

        // stack TEMPLATE FUNCTIONS
template<class _Ty,  class _Container>

inline bool operator==(const stack<_Ty, _Container>& _Left, const stack<_Ty, _Container>& _Right)
    {    // test for stack equality
    return (_Left._Get_container() == _Right._Get_container());
    }

template<class _Ty,  class _Container>

inline bool operator!=(const stack<_Ty, _Container>& _Left,  const stack<_Ty, _Container>& _Right)
    {    // test for stack inequality
    return (!(_Left == _Right));
    }

template<class _Ty, class _Container>

inline bool operator<(const stack<_Ty, _Container>& _Left, const stack<_Ty, _Container>& _Right)
    {    // test if _Left < _Right for stacks
    return (_Left._Get_container() < _Right._Get_container());
    }

template<class _Ty, class _Container>

inline bool operator>(const stack<_Ty, _Container>& _Left, const stack<_Ty, _Container>& _Right)
    {    // test if _Left > _Right for stacks
    return (_Right < _Left);
    }

template<class _Ty, class _Container>

inline bool operator<=(const stack<_Ty, _Container>& _Left, const stack<_Ty, _Container>& _Right)
    {    // test if _Left <= _Right for stacks
    return (!(_Right < _Left));
    }

template<class _Ty, class _Container>

inline bool operator>=(const stack<_Ty, _Container>& _Left, const stack<_Ty, _Container>& _Right)
    {    // test if _Left >= _Right for stacks
    return (!(_Left < _Right));
    }
_STD_END

#ifdef _MSC_VER
 #pragma warning(pop)
 #pragma pack(pop)
#endif  /* _MSC_VER */

#endif /* RC_INVOKED */
#endif /* _STACK_ */

/*
 * Copyright (c) 1992-2006 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
 */

/*
 * This file is derived from software bearing the following
 * restrictions:
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Permission to use, copy, modify, distribute and sell this
 * software and its documentation for any purpose is hereby
 * granted without fee, provided that the above copyright notice
 * appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation.
 * Hewlett-Packard Company makes no representations about the
 * suitability of this software for any purpose. It is provided
 * "as is" without express or implied warranty.
 V5.02:0009 */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

隨意的風

如果你觉得有帮助,期待你的打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值