B
Burak
void DeleteNode(struct node * & node) {
if (node->left == NULL) {
struct node *temp = node;
node = node->right;
delete temp;
} else if (node->right == NULL) {
struct node *temp = node;
node = node->left;
delete temp;
} else {
// In-order predecessor (rightmost child of left subtree)
// Node has two children - get max of left subtree
struct node **temp = &node->left; // get left node of the
original node
// find the rightmost child of the subtree of the left node
while ((*temp)->right != NULL) {
temp = &(*temp)->right;
}
// copy the value from the in-order predecessor to the
original node
node->value = (*temp)->value;
// then delete the predecessor
DeleteNode(*temp);
}
}
i saw this function on wikipedia.
what does * & mean there(struct node * & node) ?
thanx Burak
if (node->left == NULL) {
struct node *temp = node;
node = node->right;
delete temp;
} else if (node->right == NULL) {
struct node *temp = node;
node = node->left;
delete temp;
} else {
// In-order predecessor (rightmost child of left subtree)
// Node has two children - get max of left subtree
struct node **temp = &node->left; // get left node of the
original node
// find the rightmost child of the subtree of the left node
while ((*temp)->right != NULL) {
temp = &(*temp)->right;
}
// copy the value from the in-order predecessor to the
original node
node->value = (*temp)->value;
// then delete the predecessor
DeleteNode(*temp);
}
}
i saw this function on wikipedia.
what does * & mean there(struct node * & node) ?
thanx Burak