Advertisement
Guest User

CITUA

a guest
Feb 1st, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct nodo_albero{
  5. int info;
  6. struct nodo_albero *sx;
  7. struct nodo_albero *dx;
  8. };
  9.  
  10. typedef struct nodo_albero *Albero;
  11.  
  12. int* albero_cammino(Albero T, int v){
  13.  
  14. int* A = (int*)calloc(altezzafoglia(T,v),sizeof(int));
  15. int i;
  16. if(!T || !foglia(T,v))
  17. return;
  18. while(T->info != v){
  19. A[i] = T->info;
  20. i++;
  21. if(v < T->info)
  22. T = T->sx;
  23. T = T->dx;
  24. }
  25. A[i] = T->info;
  26.  
  27. return A;
  28.  
  29. }
  30.  
  31. int foglia(Albero T, int v){
  32. if(!T)
  33. return 0;
  34. else if(T->info == v && !T->sx && T->dx)
  35. return 1;
  36. else if (v < T->info)
  37. return foglia(T->sx,v);
  38. else
  39. return foglia(T->dx,v);
  40. }
  41.  
  42. int altezzafoglia(Albero T, int v){
  43. if(!T)
  44. return 0;
  45. else if(T->info == v && !T->sx && !T->dx)
  46. return 1
  47. else if(v < T->info)
  48. return 1 + altezzafoglia(T->sx,v);
  49. else
  50. return 1 + altezzafoglia(T->dx,v);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement