Advertisement
randykaur

continue

Oct 17th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct no{
  5. int elem;
  6. struct no*dir, *esq;
  7. }noArv;
  8.  
  9. noArv *insere(noArv *r, int valor){
  10. noArv *novo = (noArv *) malloc(sizeof(noArv));
  11. if(r == NULL){
  12. novo->elem=valor;
  13. novo->esq = novo->dir = NULL;
  14. return novo;
  15. }else{
  16. if(valor < r->elem){
  17. r->esq = insere(r->esq, valor);
  18. }else{
  19. r->dir = insere(r->dir, valor);
  20. }
  21.  
  22. }
  23. return r;
  24. }
  25. int main(){
  26. noArv *root = NULL;
  27. int i;
  28. for(i=0; i<MAX; i++){
  29. scanf("%d",&aux);
  30. root = insere(root,aux);
  31. }
  32. preO(root);
  33. emO(root);
  34. posO(root);
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement