Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "tree.h"
- int max(int a, int b);
- int depth(TTree *tree);
- int depth2(TNode *node);
- int main(){
- TTree arbol;
- crearArbol(&arbol);
- insertar(&arbol,15);
- insertar(&arbol,6);
- insertar(&arbol,3);
- insertar(&arbol,1);
- insertar(&arbol,4);
- insertar(&arbol,9);
- insertar(&arbol,7);
- insertar(&arbol,12);
- insertar(&arbol,20);
- insertar(&arbol,18);
- insertar(&arbol,24);
- insertar(&arbol,17);
- printf("%d\n",depth(&arbol));
- return 0;
- }
- int max(int a, int b){
- if(a>b)
- return a;
- return b;
- }
- int depth(TTree *tree){
- return depth2(tree->root);
- }
- int depth2(TNode *node){
- if(node == NULL)
- return 0;
- return 1+ max(depth2(node->izq),depth2(node->der));
- }
Add Comment
Please, Sign In to add comment