Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean verifica(Albero a, Albero b) {
- if (ricercaBinaria(b, a.val()) == true) { // PASSO BASE
- return true;
- }
- else {
- boolean latoSinistro = false;
- boolean latoDestro = false;
- if (a.sinistro != null) {
- latoSinistro = verifica(a.sinistro,b);
- }
- if (a.destro != null) {
- latoDestro = verifica(a.destro,b);
- }
- return latoSinistro || latoDestro;
- }
- }
- public static boolean ricercaBinaria(Albero b, int val) {
- if (b.val() == val) { // PASSO BASE
- return true;
- }
- else if (b.val > val && b.sinistro() != null) {
- return ricercaBinaria(b.sinistro, val);
- }
- else if (b.val < val && b.destro() != null) {
- return ricercaBinaria(b.destro, val);
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement