Example #1
0
void bsTree<T>::remove(const T & item)
{	
		TNode<T> *tN = search(root, item);					//Returns node of value, item.
		if(!tN) 											//if node is not found, remove nothing.
			return;	

		TNode<T> *pN= tN->getParent();						//Points to tN's parent.
		
		if(tN->getLeft() == NULL && tN->getRight() == NULL) //node is leaf
		{
			removeLink(tN, pN, NULL);
		}
		else if(tN->hasOnlyLeft())						    //Node has only left child
		{
			removeLink(tN, pN, tN->getLeft());
		}
		else if(tN->hasOnlyRight())						    //Node has only right child
		{
			removeLink(tN, pN, tN->getRight());
		}
		else 											    // has two children
		{
			if(tN->getValue() > root->getValue())
			{
				getSmallest(tN->getRight(), tN, tN);
			}
			else
			{
				getBiggest(tN->getLeft(), tN, tN);
			}
		}
}