Advertisement
disiodj

Esercizi_Esame_Orale

Feb 23rd, 2016
1,549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //PRIMO ESERCIZIO
  2.  
  3. int distanza(BTree t, stringa s1, stringa s2){
  4.     if(t==NULL) return 0;
  5.     BTree TS1 = cerca(&t, s1);_________________________BTree TS1 = cerca(t, s1);
  6.     if(TS1){
  7.         if(cerca(&TS1,s2))
  8.             return distanza_ric(TS1,s2);
  9.     } return 0;
  10. }
  11. BTree cerca(BTree* t, stringa s){
  12.     if((*t) == NULL) return NULL;_________________________________if(t==NULL)
  13.     if(strcmp((*t)->nome,s)==0) return (*t);_____________________if(strcmp(t->nome, s)==0) return t;
  14.     BTree sx = cerca(&(*t)->sx,s);____________________________cerca(t->sx, s);
  15.     if(sx != NULL) return sx;
  16.     else return cerca(&(*t)->dx,s);__________________cerca(t->dx,s);
  17.    
  18. }
  19. int distanza_ric(BTree t, stringa s){
  20.     if(t==NULL) return -1;
  21.     if(strcmp(t->nome,s)==0) return 0;
  22.     BTree temp = t->sx;
  23.     if(cerca(&temp,s)) return 1+distanza_ric(t->sx,s);
  24.     else 1+distanza_ric(t->dx,s);
  25. }
  26.  
  27.  
  28. //SECONDO ESERCIZIO
  29. int conta_nodi(BTree t, int x, char c){
  30.     if(t==NULL) return 0;
  31.     if(conta_occorrenza(t,c) >= x) return 1+conta_nodi(t->sx,x,c)+conta_nodi(t->dx,x,c);
  32.     return conta_nodi(t->sx,x,c)+conta_nodi(t->dx,x,c);
  33. }
  34.  
  35. //ULTIMO ESERCIZIO
  36.  
  37. int conta_figli(NTree t, int x, char c){
  38.     if(t==NULL) return 0;
  39.     NTree temp = t->primofiglio;
  40.     int cont = 0;
  41.     while(temp != NULL){
  42.         if(!strchr(temp->nome,c))
  43.             return conta_figli(t->primofiglio,x,c)+conta_figli(t->fratello,x,c);
  44.         cont++;
  45.         temp = temp->fratello;
  46.     }if(cont != x)
  47.         return conta_figli(t->primofiglio,x,c)+conta_figli(t->fratello,x,c);
  48.     return 1+conta_figli(t->primofiglio,x,c)+conta_figli(t->fratello,x,c);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement