eduardovp97

ex4.c

Nov 14th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "tree.h"
  4.  
  5. int max(int a, int b);
  6. int depth(TTree *tree);
  7. int depth2(TNode *node);
  8.  
  9. int main(){
  10.  
  11.     TTree arbol;
  12.     crearArbol(&arbol);
  13.     insertar(&arbol,15);
  14.     insertar(&arbol,6);
  15.     insertar(&arbol,3);
  16.     insertar(&arbol,1);
  17.     insertar(&arbol,4);
  18.     insertar(&arbol,9);
  19.     insertar(&arbol,7);
  20.     insertar(&arbol,12);
  21.     insertar(&arbol,20);
  22.     insertar(&arbol,18);
  23.     insertar(&arbol,24);
  24.     insertar(&arbol,17);
  25.     printf("%d\n",depth(&arbol));
  26.  
  27.  
  28.     return 0;
  29. }
  30.  
  31. int max(int a, int b){
  32.     if(a>b)
  33.         return a;
  34.     return b;
  35. }
  36.  
  37. int depth(TTree *tree){
  38.     return depth2(tree->root);
  39. }
  40.  
  41. int depth2(TNode *node){
  42.     if(node == NULL)
  43.         return 0;
  44.     return 1+ max(depth2(node->izq),depth2(node->der));
  45. }
Add Comment
Please, Sign In to add comment