fork(2) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct noh {
  5. int valor;
  6. struct noh *esquerda;
  7. struct noh *direita;
  8. } no;
  9.  
  10. void espacos(int depth) {
  11. while (depth) {
  12. printf(" ");
  13. depth--;
  14. }
  15. }
  16.  
  17. void desenha(no *arvore, int depth) {
  18. espacos(depth);
  19. if (arvore == NULL) {
  20. printf("-\n");
  21. return;
  22. }
  23. printf("%d\n", arvore->valor);
  24. desenha(arvore->esquerda, depth + 1);
  25. desenha(arvore->direita, depth + 1);
  26. }
  27.  
  28. void arvbin(no *arvore) {
  29. desenha(arvore, 0);
  30. }
  31.  
  32. int main() {
  33. no n1, n2, n3, n4, n5, n6;
  34. n1.valor = 555;
  35. n2.valor = 333;
  36. n3.valor = 888;
  37. n4.valor = 111;
  38. n5.valor = 444;
  39. n6.valor = 999;
  40. n1.esquerda = &n2;
  41. n1.direita = &n3;
  42. n2.esquerda = &n4;
  43. n2.direita = &n5;
  44. n3.esquerda = NULL;
  45. n3.direita = &n6;
  46. n4.esquerda = NULL;
  47. n4.direita = NULL;
  48. n5.esquerda = NULL;
  49. n5.direita = NULL;
  50. n6.esquerda = NULL;
  51. n6.direita = NULL;
  52. arvbin(&n1);
  53. return 0;
  54. }
Success #stdin #stdout 0s 4492KB
stdin
Standard input is empty
stdout
555
   333
      111
         -
         -
      444
         -
         -
   888
      -
      999
         -
         -