Binary Search Tree Delete

This is the delete function of binary search tree. However it won't enter the if-else statement that checks whether the node to be deleted is the left child or right child. Can someone please help?

void DeleteNode(node* T, int number)
{
node* x = new node;
node* current = new node;
node* dele = new node;
node* finder = new node;
finder = root;


while(finder!=NULL && number!=finder->key)
{
if(finder->key < number)
finder = finder->right;
else
finder = finder->left;
}
dele = finder;

if(dele->left == NULL || dele->right == NULL)
{current = dele;

}
else //Tree Successor
{
if(dele->right != NULL)
{
while(dele->left!=NULL) //Tree Minimum
{
dele = dele->parent;
}
current = dele;
}
else
{
current = dele->parent;
while(current!=NULL && dele==current->right)
{
dele = current;
current = current->parent;
}
}
}
if(current->left != NULL)
x = current->left;
else
{
x = current->right;
}


if(x != NULL)
{
x->parent = current->parent;
}

if(current->parent = NULL)
{root = x;

}

else{

if(current==current->parent->left)
{
current->parent->left = x;
}
else
{
current->parent->right = x;
}
}

if(current!=dele)
{
dele->key = current->key;
delete current;
}
}
I understand nothing in this code. I only see that there are numerous memory leaks.:)

And what does the first parameter node *T mean?
Last edited on
Please enclose your code in code tags, to make it easier to read.
Topic archived. No new replies allowed.