Advertisement
Jerkiller

conta nodi centrali

Jan 27th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. int contanodicentrali(Node r, int sum, int *foglie){
  2.   int nodi, nodisx, nodidx, numfsx, numfdx;
  3.   if(r==NULL){
  4.     *foglie=0;
  5.     return 0;
  6.   }
  7.  
  8.   if((r->left==NULL)&&(r->right==NULL)){
  9.     *foglie=1;
  10.     return 0;
  11.   }
  12.  
  13.   else{
  14.     nodisx=contanodicentrali(r->left, sum+r->key, &numfsx);
  15.     nodidx=contanodicentrali(r->right, sum+r->key, &numfdx);
  16.     *foglie=numfsx+numfdx;
  17.     nodi=nodisx+nodidx;
  18.   }
  19.  
  20.   if(sum+r->key==*foglie)nodi++;
  21.  
  22.   return nodi;
  23. }
  24.  
  25.  
  26.  
  27.  
  28. void main(){
  29.   Node r;
  30.   int numf;
  31.   int nodicentrali=contanodicentrali(r,0,&numf);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement