⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 container.h

📁 representation of a binary search tree
💻 H
字号:
#ifndef CONTAINER_H#define CONTAINER_H#include <iostream>#include <string>class Streamable {	virtual std::ostream& put( std::ostream& o ) const = 0;	friend std::ostream& operator<<( std::ostream& o, const Streamable& s );public:	virtual ~Streamable( ) {};};inline std::ostream& operator<<( std::ostream& o, const Streamable& s ) { return s.put( o ); }typedef unsigned long int ValueType;class Key {	ValueType value;	Key( ValueType v ) : value( v ) {}public:	Key() {}	~Key( ) {}	std::ostream& put( std::ostream& o ) const { return o << value; }	std::istream& get( std::istream& i ) { return i >> value; }	bool operator==( const Key& k ) const { return value == k.value; }	bool operator>( const Key& k ) const { return value > k.value; }	unsigned long ulongValue() const { return (unsigned long) value; }	unsigned long hashValue() const { return (unsigned long) value; }	friend class KeyFactory;};inline std::ostream& operator<<( std::ostream& o, const Key& s ) { return s.put( o ); }inline std::istream& operator>>( std::istream& i, Key& s ) { return s.get( i ); }class KeyFactory {public:	static Key newKey( unsigned long v ) { return Key( v ); }	static Key newKey( ) { return Key( std::rand( ) ); }	static void srand( int i ) { std::srand( i ); }};class Container : public Streamable {protected:	Container( ) { }public:	enum Order { dontcare, ascending, descending };	class Functor;	class Exception;	virtual ~Container( ) { }	virtual void add( const Key& key ) { add( &key, 1 ); }	virtual void add( const Key keys[], size_t size ) = 0;	virtual void remove( const Key& key ) { remove( &key, 1 ); }	virtual void remove( const Key keys[], size_t size ) = 0;	virtual bool isMember( const Key& key ) const = 0;	virtual size_t size( ) const = 0;	virtual bool isEmpty( ) const { return size( ) == 0; }	virtual void foreach( const Functor& f, Order order = dontcare ) const = 0;	virtual Key minKey( ) const = 0;	virtual Key maxKey( ) const = 0;	virtual int teamNr( ) const = 0;	virtual int themeNr( ) const = 0;};class Container::Exception : public Streamable {	std::string msg;	virtual std::ostream& put( std::ostream& o ) const { return o << "Container::Exception (" << msg << ")"; }public:	Exception( const std::string& msg ) : msg( msg ) {}	const std::string& getMsg() const { return msg; }	virtual ~Exception( ) {}};class Container::Functor {public:	virtual bool operator( )( const Key& key ) const = 0;	virtual ~Functor( ) {}};#endif //CONTAINER_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -