disiodj

HOMEWORK4_Ese2

Jan 2nd, 2016
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  main.c
  3. //  Homework4_Ese2
  4. //
  5. //  Created by gabriele cugliari on 02/01/16.
  6. //  Copyright (c) 2016 gabriele cugliari. All rights reserved.
  7. //
  8.  
  9. #include<stdio.h>
  10. #include<stdlib.h>
  11.  
  12. struct nodo_albero{
  13.     int info;
  14.     struct nodo_albero *sx;
  15.     struct nodo_albero *dx;
  16. };
  17.  
  18. /* scrivi qui la definizione del tipo albero che rappresenta un puntatore alla struttura nodo_albero */
  19.  
  20. typedef struct nodo_albero *albero;
  21.  
  22. int max(int n, int m){
  23.     if(n>m)
  24.         return n;
  25.     else
  26.         return m;
  27. }
  28.  
  29. int Height(albero n){
  30.     if(n)
  31.         return 1+max(Height(n->sx), Height(n->dx));
  32.     else
  33.         return -1;
  34. }
  35. int Albero_completoRic(albero T,int k){
  36.     if(T==NULL && k!=-1)
  37.         return 0;
  38.     if(T==NULL && k==-1)
  39.         return 1;
  40.     if((T->dx!=NULL && T->sx==NULL) || (T->dx==NULL && T->sx!=NULL))
  41.         return 0;
  42.     return (Albero_completoRic(T->dx,k-1))&& (Albero_completoRic(T->sx,k-1));
  43. }
  44.  
  45. int albero_completo(albero T){
  46.     if(T==NULL)
  47.         return 0;
  48.     return Albero_completoRic(T, Height(T));
  49.    
  50. }
Add Comment
Please, Sign In to add comment