//+------------------------------------------------------------------------- // // Microsoft Windows // // Copyright (C) Microsoft Corporation, 1994 - 1999 // // File: splaytre.hxx // //-------------------------------------------------------------------------- //////////////////////////////////////////////////////////// // // File name: splaytree.hxx // // Title: Splay Tree class // // Desciption: // // Author: Scott Holden (t-scotth) // // Date: August 16, 1994 // //////////////////////////////////////////////////////////// #ifndef _SPLAY_TREE_HXX_ #define _SPLAY_TREE_HXX_ typedef int BOOLEAN; #define TRUE 1 #define FALSE 0 #define NULL 0 template class SplayTree; template class SplayNode { friend class SplayTree; private: SplayNode *_Parent; SplayNode *_RightChild; SplayNode *_LeftChild; T *_Data; SplayNode( ) : _Data( NULL ), _Parent( NULL ), _RightChild( NULL ), _LeftChild( NULL ) { } SplayNode( T *a ) : _Data( a ), _Parent( NULL ), _RightChild( NULL ), _LeftChild( NULL ) { } ~SplayNode() { } }; template class SplayTree { friend class SplayNode; private: SplayNode *_Root; unsigned int _Size; void Splay ( SplayNode * ); // returns pointer to the root of the tree void Delete( SplayNode * ); SplayNode* InsertAsRightChild( SplayNode *, SplayNode * ); SplayNode* InsertAsLeftChild ( SplayNode *, SplayNode * ); BOOLEAN IsRoot ( SplayNode *a ) { return ( a == _Root ? TRUE : FALSE ); } BOOLEAN IsRightChild( SplayNode *a ) { if ( a->_Parent != NULL) { return ( a == a->_Parent->_RightChild ? TRUE : FALSE ); } return FALSE; } BOOLEAN IsLeftChild( SplayNode *a ) { if ( a->_Parent != NULL ) { return ( a == a->_Parent->_LeftChild ? TRUE : FALSE ); } return FALSE; } SplayNode* Successor ( SplayNode * ); SplayNode* Predecessor ( SplayNode * ); SplayNode* SubtreeSuccessor ( SplayNode * ); SplayNode* SubtreePredecessor( SplayNode * ); SplayNode* Find( SplayNode *, T * ); SplayNode* MaximumNode( ); SplayNode* MinimumNode( ); public: //SplayTree() : _Root( NULL ), _Size( 0 ) { } SplayTree( T *a = NULL ) : _Root( NULL ), _Size( 0 ) { if ( a != NULL ) { Insert( a ); } } ~SplayTree(); void Insert( T * ); T* Find ( T * ); T* Delete( T * ); T* Minimum( ) { SplayNode *Temp = MinimumNode( ); return Temp->_Data; } T* Maximum( ) { SplayNode *Temp = MaximumNode( ); return Temp->_Data; } T* Successor ( T * ); T* Predecessor( T * ); unsigned int Size() { return _Size; } #ifdef DEBUGRPC void Print( ); unsigned int Depth( ) { return Depth( _Root, 0 ); } private: void Print( SplayNode * ); unsigned int Depth( SplayNode *, unsigned int ); #endif // DEBUGRPC }; #include "splaytre.inl" #endif // _SPLAY_TREE_HXX_