C++ young 程序库——y_queue.hpp 和 y_stack.hpp
来源:互联网 发布:秒赞网源码免授权 编辑:程序博客网 时间:2024/06/05 23:44
文件位置:young/y_queue.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.
*/
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#ifndef __MACRO_CPLUSPLUS_YOUNG_LIBRARY_QUEUE_HEADER_FILE__
#define __MACRO_CPLUSPLUS_YOUNG_LIBRARY_QUEUE_HEADER_FILE__
//-----------------------------------------------------------------------------
#include "y_functional.hpp"
#include "y_deque.hpp"
#include "y_vector.hpp"
#include "algorithm/y_algorithm_heap.hpp"
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_YOUNG_LIBRARY_BEGIN_NAMESPACE__
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template< typename T, typename Container = deque<T> >
class queue
{
public:
typedef queue<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;
private:
Container con;
public:
explicit queue( const Container& other = Container() ) : con(other) {}
bool empty() const { return con.empty(); }
size_type size() const { return con.size(); }
reference front() { return con.front(); }
const_reference front() const { return con.front(); }
reference back() { return con.back(); }
const_reference back() const { return con.back(); }
void push( const_reference x ) { con.push_back(x); }
void pop() { con.pop_front(); }
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( queue<T, Container>& lhs, queue<T, Container>& rhs )
{
lhs.swap( rhs );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template< typename T, typename Container = vector<T>,
typename Compare = less<typename Container::value_type> >
class priority_queue
{
public:
typedef priority_queue<T, Container, Compare> 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;
private:
Container con;
Compare comp;
public:
explicit priority_queue( const Compare& cmp = Compare() )
: con(), comp(cmp) {}
template< typename InputIterator >
priority_queue( InputIterator first, InputIterator last )
: con(first, last), comp()
{
make_heap( con.begin(), con.end(), comp );
}
template< typename InputIterator >
priority_queue( InputIterator first, InputIterator last, const Compare& cmp )
: con(first, last), comp(cmp)
{
make_heap( con.begin(), con.end(), comp );
}
bool empty() const { return con.empty(); }
size_type size() const { return con.size(); }
const_reference top() const { return con.front(); }
void swap( self& rhs ) { con.swap( rhs.con ); }
void push( const_reference value )
{
con.push_back( value );
push_heap( con.begin(), con.end(), comp );
}
void pop()
{
pop_heap( con.begin(), con.end(), comp );
con.pop_back();
}
};
template< typename T, typename Container, typename Compare >
inline void swap( priority_queue<T, Container, Compare>& lhs,
priority_queue<T, Container, Compare>& rhs )
{
lhs.swap( rhs );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_YOUNG_LIBRARY_END_NAMESPACE__
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
文件位置:young/y_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.
*/
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#ifndef __MACRO_CPLUSPLUS_YOUNG_LIBRARY_STACK_HEADER_FILE__
#define __MACRO_CPLUSPLUS_YOUNG_LIBRARY_STACK_HEADER_FILE__
//-----------------------------------------------------------------------------
#include "y_deque.hpp"
//-----------------------------------------------------------------------------
__MACRO_CPLUSPLUS_YOUNG_LIBRARY_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_YOUNG_LIBRARY_END_NAMESPACE__
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
- C++ young 程序库——y_queue.hpp 和 y_stack.hpp
- C++ young 程序库——y_iterator.hpp 和 y_type_traits.hpp
- C++ young 程序库——y_pair.hpp 和 y_initialization.hpp
- C++ young 程序库——y_char_function.hpp 和 y_char_traits.hpp
- C++ young 程序库——y_optm_string.hpp 和 y_string.hpp
- C++ young 程序库——y_set.hpp 和 y_map.hpp
- C++ young 程序库——y_hash_set.hpp 和 y_hash_map.hpp
- C++ young 程序库——y_pointer.hpp、y_ptr_container.hpp、y_temp_buffer.hpp 和 y_memory.hpp
- C++ young 程序库——y_allocator.hpp 、y_construct.hpp 和 y_exception.hpp
- C++ young 程序库——y_binary_search_tree_base.hpp、y_red_black_tree_base.hpp 和 y_red_black_tree.hpp
- C++ young 程序库——y_hash_function.hpp、y_hash_table_base.hpp 和 y_hash_table.hpp
- C++ young 程序库——y_algorithm_base.hpp、y_algorithm_compare.hpp、y_algorithm_copy.hpp、y_algorithm_fill.hpp、y_algorithm_lower_bound.hp
- C++ young 程序库——y_define.hpp
- C++ young 程序库——y_basic_string.hpp
- C++ young 程序库——y_vector.hpp
- C++ young 程序库——y_deque.hpp
- C++ young 程序库——y_list.hpp
- C++ young 程序库——y_slist.hpp
- 通过JDBC连接oracle数据库的十大技巧
- C++ young 程序库——y_hash_set.hpp 和 y_hash_map.hpp
- C++ young 程序库——y_numeric.hpp
- C++ young 程序库——y_pointer.hpp、y_ptr_container.hpp、y_temp_buffer.hpp 和 y_memory.hpp
- 实现真彩色的按钮
- C++ young 程序库——y_queue.hpp 和 y_stack.hpp
- JAVA 中 jar 文件的编写和应用
- 讲解关于编写跨平台Java程序时的注意事项 选择自 tiewen 的 Blog
- JAVA代码编写的30条建议
- Eclipse及其插件介绍和下载
- (转载)[TOMCAT]用web.xml控制Web应用的行为
- oracle里常用命令 选择自 mfc2003 的 Blog
- 各类语言的.NET版本列表
- http://web.archive.org/