コード例 #1
0
//Recursively Remove data from the Tree
void BinaryTree::rRemove(string s, TreeNode*& that) {

	//Error Handling
	if (that == NULL) return;

	//Base Case
	if (s == that->data) { remNode(that);			return; }
	if (s <= that->data) { rRemove(s, that->left);	return; }
	if (s >  that->data) { rRemove(s, that->rght);	return; }

	cout << "Recursive Delete has Failed" << endl;
	return;
}
コード例 #2
0
BinaryNode *BinarySearchTree::rRemove(int x, BinaryNode *t) //throw (ItemNotFound)
{ 
	if(t == NULL)
		throw runtime_error("ITEM NOT FOUND");
	if(x < t->key)
		t->left = rRemove(x, t->left);
	else if(x > t->key)
		t->right = rRemove(x, t->right);
	else if(t->left != NULL && t->right != NULL)// item x is found; t has two children
	{
		t->key = findMin(t->right)->key;
		t->right = removeMin(t->right);
	} 
	else { //t has only one child
		BinaryNode *node = t;
		t = (t->left != NULL) ? t->left : t->right;
		delete node;
	}
	return t;
}
コード例 #3
0
//Remove data from the Tree
void BinaryTree::remove(string s) 	{ rRemove(s, root); return; }