C'è questa function per verificare se un albero è perfettamente bilanciato:
Vorrei sapere come funziona questa parte.codice:bilanciato(root, 0, -1) function bilanciato(root, altezza, h_temp) if(root = NULL) then if(altezza = 0) altezza=h_temp else if(altezza != h_temp) bilanciato := false endif bilanciato:=true endif if( (bilanciato(root->left, height, h_temp+1) ) bilanciato(root.right, altezza, h_temp+1) endif bilanciato:=false; end
Inizialmente supponiamo di avere la root che è != NULL, entra nel secondo if e cosa succede?codice:if( (bilanciato(root->left, height, h_temp+1) ) bilanciato(root.right, altezza, h_temp+1) endif

Rispondi quotando