Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. typedef struct nodo {
  6.     char dado;
  7.     struct nodo *esq,*dir;
  8. }arvore;
  9.  
  10.  
  11.  
  12. void Constroi(arvore **eainicio) {
  13.     char c;
  14.  
  15.     FILE *arq;
  16.     arq = fopen("./t1.txt","a");
  17.     rewind(arq);
  18.     c = getc(arq);
  19.  
  20.  
  21.  
  22.     if (c == '.')
  23.         *eainicio = NULL;
  24.  
  25.     else
  26.     {
  27.         *eainicio = malloc (sizeof (arvore));
  28.         (*eainicio)->dado = c;
  29.         Constroi (&((*eainicio)->esq));
  30.         Constroi (&((*eainicio)->dir));
  31.     }
  32.  
  33. }
  34.  
  35. void LeArv(arvore *ainicio)
  36. {
  37.     if (ainicio == NULL)
  38.     printf (".");
  39.     else {
  40.     printf ("%c" , ainicio->dado);
  41.     LeArv (ainicio->esq);
  42.     LeArv (ainicio->dir);
  43.     }
  44. }
  45.  
  46.  
  47. int main ()
  48. {
  49.  
  50.     arvore *a1;
  51.  
  52.  
  53.     Constroi(&a1);
  54.     LeArv(a1);
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement