fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct arvore {
  4. unsigned int n;
  5. struct arvore *esq, *dir;
  6. } arvore;
  7.  
  8. void destruir_arvore(arvore *no) {
  9. if (no == NULL) return;
  10.  
  11. arvore *nos_abertos[1024];
  12.  
  13. nos_abertos[0] = no;
  14. int qtd = 1;
  15.  
  16. while (qtd > 0) {
  17. arvore *ultimo = nos_abertos[qtd - 1];
  18. if (ultimo->esq != NULL) {
  19. nos_abertos[qtd] = ultimo->esq;
  20. ultimo->esq = NULL;
  21. qtd++;
  22. } else if (ultimo->dir != NULL) {
  23. nos_abertos[qtd] = ultimo->dir;
  24. ultimo->dir = NULL;
  25. qtd++;
  26. } else {
  27. free(nos_abertos[qtd]);
  28. qtd--;
  29. }
  30. }
  31. }
  32.  
  33. int main(int argc, char** argv) {
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 4496KB
stdin
Standard input is empty
stdout
Standard output is empty