SOLUCIÓN AL EJERCICIO Nš 4 DE ÁRBOLES GENERALES


Las funciones son las siguientes:

void EscribirArbol(nodo n,tArbol t)
{
  nodo m;
  int et;

  if(n==NODO_NULO)
    Escribir(FINAL);
  else{
    EtiquetaArbol(&et,n,t);
    Escribir(et);
    if (HijoIzqda(n,t)==NODO_NULO)
      Escribir(FINAL);
    else for(m=HijoIzqda(n,t);m!=NODO_NULO;m=HermanoDrcha(m,t))
           EscribirArbol(m,t);
    if (HermanoDrcha(n,t)==NODO_NULO)
      Escribir(FINAL);
  }
}


tArbol LeerArbol(void)
{
  tArbol Ai,Ad,A;
  int et;
  nodo n;

  et=Leer();

  if(et==FINAL)
    return ARBOL_VACIO;
  else{
    A=CrearRaiz(&et,sizeof(int));
    Ai=LeerArbol();
    if (Ai!=ARBOL_VACIO){
      InsertarHijoIzqda(Raiz(A),Ai,A);
      n=HijoIzqda(Raiz(A),A);
      for(Ad=LeerArbol();Ad!=ARBOL_VACIO;Ad=LeerArbol()){
        InsertarHermanoDrcha(n,Ad,A);
        n=HermanoDrcha(n,A);
      }
    }
  }
  return A;

}