Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Implemente una función que reciba como parámetro un ABB y determine si existen o no valores
- repetidos en dicho árbol (Traducción Libre de [SW11] - Modificado).
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "tree.h"
- int hayRepetidos(TTree *tree);
- int hayRepetidosAux(TNode *node);
- int main(){
- TTree arbol;
- crearArbol(&arbol);
- insertar(&arbol,15);
- insertar(&arbol,6);
- insertar(&arbol,3);
- insertar(&arbol,1);
- insertar(&arbol,4);
- insertar(&arbol,9);
- insertar(&arbol,7);
- insertar(&arbol,12);
- insertar(&arbol,20);
- insertar(&arbol,18);
- insertar(&arbol,24);
- insertar(&arbol,17);
- printf("%d\n",hayRepetidos(&arbol));
- return 0;
- }
- int hayRepetidos(TTree *tree){
- if(tree->root == NULL)
- return -1;
- return hayRepetidosAux(tree->root);
- }
- int hayRepetidosAux(TNode *node){
- if(node == NULL)
- return 0;
- if(node->izq != NULL && node->info == node->izq->info)
- return 1;
- if(node->der != NULL && node->info == node->der->info)
- return 1;
- return hayRepetidosAux(node->izq) || hayRepetidosAux(node->der);
- }
Add Comment
Please, Sign In to add comment