Advertisement
gonzalob

Untitled

Oct 26th, 2021
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1.  
  2. nodoArbol * borrar(nodoArbol * arbol, int dato)
  3. {
  4.     if (arbol == NULL) //cuando el arbol no tiene info
  5.     {
  6.         //fin de todo
  7.     }
  8.     else //cuando el arbol tiene info
  9.     {
  10.         if (dato == arbol->dato)
  11.         {
  12.             //encontre el nodo
  13.             if (arbol->izq !=NULL)
  14.             {
  15.                 nodoArbol * masDer = NMD(arbol->izq); //13
  16.                 arbol->dato = masDer->dato; //reemplazo 15 x 13, 15 out
  17.                 arbol->izq = borrar(arbol->izq,masDer->dato); //todo de vuelta pero con el 13
  18.             }
  19.             else (arbol->der!=NULL)
  20.             {
  21.                 nodoArbol * masIzq = NMI(arbol->der); //18
  22.                 arbol->dato = masIzq->dato; //reemplazo 15 x 18, 15 out
  23.                 arbol->der = borrar(arbol->der,masIzq->dato); //todo de vuelta pero con el 18
  24.             }
  25.             if ((arbol->izq == NULL) && (arbol->der == NULL))
  26.             {
  27.                 free(arbol);
  28.                 arbol = NULL;
  29.             }
  30.         }
  31.         else if (dato > arbol->dato) //continuamos la recursion buscando el dato
  32.         {
  33.             arbol->der = borrar(arbol->der,dato);
  34.         }
  35.         else if (dato < arbol->dato)
  36.         {
  37.             arbol->izq = borrar(arbol->izq,dato);
  38.         }
  39.     }
  40.     return arbol;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement