Example #1
0
/*
	testRemoveNode: function to test the left most element
	param: tree - the tree we are testing
	pre: tree is not null
	post: 3 nodes have been removed from the tree
*/
void testRemoveNode(struct BSTree *tree) {

    removeNodeFromTree(tree, 13);
    /* Should output: node is not contained in the tree */

    removeNodeFromTree(tree, 20);
    printTestResult(tree->root->val == 55 && tree->root->left->left == NULL, "removeNodeFromTree", "remove left-left of root");

    removeNodeFromTree(tree, 36);
    printTestResult(compareValues(tree->root->val, 55) == 0 && tree->root->left == NULL, "removeNodeFromTree", "remove left of root");

    removeNodeFromTree(tree, 67);
    printTestResult(compareValues(tree->root->val, 55) == 0 && tree->root->right->left == NULL, "removeNodeFromTree", "remove right-left of root");

    /* Comment out these test cases and try some more interesting ones */


}
void PlanarSubgraphPQTree::
removeEliminatedLeaves(SList<PQLeafKey<edge,whaInfo*,bool>*> &eliminatedKeys)
{
	PQNode<edge,whaInfo*,bool>*  nodePtr = 0;
	PQNode<edge,whaInfo*,bool>*  parent  = 0;
	PQNode<edge,whaInfo*,bool>*  sibling = 0;

	SListIterator<PQLeafKey<edge,whaInfo*,bool>*> it;
	for (it = eliminatedKeys.begin(); it.valid(); it++)
	{
		nodePtr = (*it)->nodePointer();
		parent = nodePtr->parent();
		sibling = nodePtr->getNextSib(NULL);

		removeNodeFromTree(parent,nodePtr);
		checkIfOnlyChild(sibling,parent);
		if (parent->status() == TO_BE_DELETED)
		{
			parent->status(WHA_DELETE);
		}
		nodePtr->status(WHA_DELETE);
	}
}