Created
July 6, 2015 23:33
-
-
Save joffilyfe/ac01aad20d027671b2da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Arvore* remove_node(Arvore *arv, int d) { | |
if (arv == NULL) return NULL; | |
if (arv->dado > d) { | |
arv->esquerda = remove_node(arv->esquerda, d); | |
} else if (arv->dado < d) { | |
arv->direita = remove_node(arv->direita, d); | |
} else { | |
if (arv->esquerda == NULL && arv->direita == NULL) { | |
free(arv); | |
arv = NULL; | |
} else if (arv->esquerda == NULL) { | |
// printf("Filho a direita\n"); | |
Arvore *aux = arv; | |
arv = arv->direita; | |
free(aux); | |
} else if (arv->direita == NULL) { | |
Arvore *aux = arv; | |
arv = arv->esquerda; | |
free(aux); | |
} else { | |
Arvore *aux = arv->esquerda; | |
while(aux->direita != NULL) { | |
aux = aux->direita; | |
} | |
// printf("[%d]\n", aux->dado); | |
arv->dado = aux->dado; | |
aux->dado = d; | |
arv->esquerda = remove_node(arv->esquerda, d); | |
} | |
} | |
return arv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment