**fig4_26.txt** /* 1*/ template /* 2*/ void /* 3*/ Binary_Search_Tree:: /* 4*/ Remove( const Etype & X, Tree_Node * & T ) /* 5*/ { /* 6*/ Tree_Node *Tmp_Cell; /* 7*/ if( T == NULL ) /* 8*/ Error( "Element not found" ); /* 9*/ else /*10*/ if( X < T->Element ) // Go left. /*11*/ Remove( X, T->Left ); /*12*/ else /*13*/ if( X > T->Element ) // Go right. /*14*/ Remove( X, T->Right ); /*15*/ else // Found element to be removed. /*16*/ if( T->Left != NULL && T->Right != NULL ) // Two children. /*17*/ { // Replace with smallest in right subtree. /*18*/ Tmp_Cell = Find_Min( T->Right ); /*19*/ T->Element = Tmp_Cell->Element; /*20*/ Remove( T->Element, T->Right ); /*21*/ } /*22*/ else // One or zero child. /*23*/ { /*24*/ Tmp_Cell = T; /*25*/ if( T->Left == NULL ) // Only a right child. /*26*/ T = T->Right; /*27*/ else /*28*/ if( T->Right == NULL ) // Only a left child. /*29*/ T = T->Left; /*30*/ delete Tmp_Cell; /*31*/ } /*32*/ }