📄 mstl_stack.hpp
字号:
/*
The young Library
Copyright (c) 2005 by 杨桓
Permission to use, copy, modify, distribute and sell this software 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.
The author make no representations about the suitability of this software
for any purpose. It is provided "as is" without express or implied warranty.
*/
/*
* 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.
*/
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#ifndef __MACRO_CPLUSPLUS_MINI_STL_STACK_HEADER_FILE__
#define __MACRO_CPLUSPLUS_MINI_STL_STACK_HEADER_FILE__
//-----------------------------------------------------------------------------
#include "mstl_deque.hpp"
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_MINI_STL_BEGIN_NAMESPACE__
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template< typename T, typename Container = deque<T> >
class stack
{
public:
typedef stack<T, Container> self;
typedef Container container_type;
typedef typename Container::value_type value_type;
typedef typename Container::reference reference;
typedef typename Container::const_reference const_reference;
typedef typename Container::pointer pointer;
typedef typename Container::const_pointer const_pointer;
typedef typename Container::size_type size_type;
typedef typename Container::difference_type difference_type;
protected:
Container con;
public:
explicit stack( const Container& other = Container() ) : con(other) {}
bool empty() const { return con.empty(); }
size_type size() const { return con.size(); }
reference top() { return con.back(); }
const_reference top() const { return con.back(); }
void push( const_reference x ) { con.push_back( x ); }
void pop() { con.pop_back(); }
void swap( self& rhs ) { con.swap( rhs.con ); }
bool operator==( const self& rhs ) const { return ( con == rhs.con ); }
bool operator!=( const self& rhs ) const { return ( con != rhs.con ); }
bool operator<( const self& rhs ) const { return ( con < rhs.con ); }
bool operator>( const self& rhs ) const { return ( con > rhs.con ); }
bool operator<=( const self& rhs ) const { return ( con <= rhs.con ); }
bool operator>=( const self& rhs ) const { return ( con >= rhs.con ); }
};
template< typename T, typename Container >
inline void swap( stack<T, Container>& lhs, stack<T, Container>& rhs )
{
lhs.swap( rhs );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_MINI_STL_END_NAMESPACE__
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -