Advertisement
davegimo

Untitled

Apr 20th, 2019
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. public static boolean SottoAlberi(Albero A, Albero B) {
  2.  
  3.     int sommaA = somma(A.sinistro());
  4.     int sommaB = somma(B.destro());
  5.  
  6.     if (sommaA == sommaB) {
  7.         return true;
  8.     }
  9.     else {
  10.         return false;
  11.     }
  12. }
  13.  
  14. public static int somma(Albero L) {
  15.  
  16.     if (L.sinistro() == null && L.destro() == null) { // passo base, รจ foglia!
  17.         return L.val();
  18.     }
  19.  
  20.     int conta = 0;
  21.  
  22.     if (L.sinistro != null) {
  23.         conta += somma(L.sinistro());
  24.     }
  25.  
  26.     if (L.destro != null) {
  27.         conta += somma(L.destro());
  28.     }
  29.  
  30.     return conta;
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement