// wzbintree.h #ifndef _PROGRAMCOMMON_WZBINTREE_H_ #define _PROGRAMCOMMON_WZBINTREE_H_ #include "wztypedef.h" //------------------------------------------------------------------------------ /** @class CWzBinTree */ template class CWzBinTree { public: // »ý¼ºÀÚ/¼Ò¸êÀÚ CWzBinTree( void ); ~CWzBinTree( void ); // ¿ÞÂÊ¿¡ Ãß°¡(Ãß°¡µÈ Æ®¸® ¹Ýȯ) CWzBinTree* AddLeft( void ); // ¿À¸¥ÂÊ¿¡ Ãß°¡(Ãß°¡µÈ Æ®¸® ¹Ýȯ) CWzBinTree* AddRight( void ); // ¿ÞÂÊ Æ®¸® ¼³Á¤ void SetLeft( CWzBinTree* left ); // ¿ÞÂÊ Æ®¸® ¾ò±â CWzBinTree* GetLeft( void ) const; // ¿À¸¥ÂÊ Æ®¸® ¼³Á¤ void SetRight( CWzBinTree* right ); // ¿À¸¥ÂÊ Æ®¸® ¾ò±â CWzBinTree* GetRight( void ) const; // ºÎ¸ð Æ®¸® ¾ò±â CWzBinTree* GetParent( void ) const; // µ¥ÀÌŸ ¼³Á¤ void SetData( const T& data ); // µ¥ÀÌŸ ¾ò±â const T& GetData( void ) const; // Àüü Á¦°Å void Destroy( void ); private: // ¿ÞÂÊ Æ®¸® Á¦°Å void DeleteLeft( void ); // ¿À¸¥ÂÊ Æ®¸® Á¦°Å void DeleteRight( void ); private: CWzBinTree* m_left; CWzBinTree* m_right; CWzBinTree* m_parent; T m_data; }; //------------------------------------------------------------------------------ /** */ template CWzBinTree::CWzBinTree( void ) : m_left( NULL ) , m_right( NULL ) , m_parent( NULL ) { // empty } //------------------------------------------------------------------------------ /** */ template CWzBinTree::~CWzBinTree( void ) { // empty } //------------------------------------------------------------------------------ /** */ template void CWzBinTree::Destroy( void ) { DeleteLeft(); DeleteRight(); } //------------------------------------------------------------------------------ /** */ template void CWzBinTree::DeleteLeft( void ) { if( m_left ) { m_left->Destroy(); delete m_left; m_left = NULL; } } //------------------------------------------------------------------------------ /** */ template void CWzBinTree::DeleteRight( void ) { if( m_right ) { m_right->Destroy(); delete m_right; m_right = NULL; } } //------------------------------------------------------------------------------ /** */ template CWzBinTree* CWzBinTree::AddLeft( void ) { CWzBinTree* newTree = new CWzBinTree; WzAssert( newTree ); SetLeft( newTree ); return newTree; } //------------------------------------------------------------------------------ /** */ template CWzBinTree* CWzBinTree::AddRight( void ) { CWzBinTree* newTree = new CWzBinTree; WzAssert( newTree ); SetRight( newTree ); return newTree; } //------------------------------------------------------------------------------ /** */ template void CWzBinTree::SetLeft( CWzBinTree* left ) { DeleteLeft(); if( left ) { m_left = left; left->m_parent = this; } } //------------------------------------------------------------------------------ /** */ template CWzBinTree* CWzBinTree::GetLeft( void ) const { return m_left; } //------------------------------------------------------------------------------ /** */ template void CWzBinTree::SetRight( CWzBinTree* right ) { DeleteRight(); if( right ) { m_right = right; right->m_parent = this; } } //------------------------------------------------------------------------------ /** */ template CWzBinTree* CWzBinTree::GetRight( void ) const { return m_right; } //------------------------------------------------------------------------------ /** */ template CWzBinTree* CWzBinTree::GetParent( void ) const { return m_parent; } //------------------------------------------------------------------------------ /** */ template void CWzBinTree::SetData( const T& data ) { m_data = data; } //------------------------------------------------------------------------------ /** */ template const T& CWzBinTree::GetData( void ) const { return m_data; } #endif // _PROGRAMCOMMON_WZBINTREE_H_