Advertisement
davegimo

Untitled

Apr 4th, 2019
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. public static boolean verifica(Albero a, Albero b) {
  2.  
  3.     if (ricercaBinaria(b, a.val()) == true) {  // PASSO BASE
  4.         return true;
  5.     }
  6.  
  7.     else {
  8.         boolean latoSinistro = false;  
  9.         boolean latoDestro = false;
  10.  
  11.         if (a.sinistro != null) {
  12.             latoSinistro = verifica(a.sinistro,b);
  13.         }
  14.  
  15.         if (a.destro != null) {
  16.             latoDestro = verifica(a.destro,b);
  17.         }
  18.  
  19.         return latoSinistro || latoDestro;
  20.     }
  21. }
  22.  
  23. public static boolean ricercaBinaria(Albero b, int val) {
  24.  
  25.     if (b.val() == val) {  // PASSO BASE
  26.         return true;
  27.     }
  28.  
  29.     else if (b.val > val && b.sinistro() != null) {
  30.         return ricercaBinaria(b.sinistro, val);
  31.     }
  32.  
  33.     else if (b.val < val && b.destro() != null) {
  34.         return ricercaBinaria(b.destro, val);
  35.     }
  36.  
  37.     return false;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement