Ancora alberi
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import static java.lang.Math.max;
|
||||
|
||||
class Nodo{
|
||||
int dato;
|
||||
Nodo left, right;
|
||||
@@ -62,6 +64,11 @@ class Nodo{
|
||||
else if(livello==0) return albero.dato + " ";
|
||||
else return valoriNelLivello(albero.left, livello-1) + valoriNelLivello(albero.right, livello-1);
|
||||
}
|
||||
static int altezza(Nodo albero){
|
||||
if(albero==null) return 0;
|
||||
else if (albero.left == null && albero.right == null) return 1;
|
||||
return 1 + max(altezza(albero.left), altezza(albero.right));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user