Skip to content

Instantly share code, notes, and snippets.

@vyruz
Last active December 12, 2015 00:49
Show Gist options
  • Save vyruz/4686680 to your computer and use it in GitHub Desktop.
Save vyruz/4686680 to your computer and use it in GitHub Desktop.
void remove_recursively(bt_node* top, int data){
if(top->data == data){
if(top->right == NULL && top->left == NULL){
top->data = NULL;
}else{
if(top->data < data){
remove_recursively(top->left, data);
}else{
remove_recursively(top->right, data);
}
}
}
}
void remove(bt_node** top_ref, int data) {
// implement me
if(*top_ref == NULL){
return;
}else{
if(*top_ref->data == data){
if(*top_ref->left == NULL && *top_ref->right == NULL){
*top_ref->data = NULL;
}
}else{
remove_recursively(*top_ref, data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment