All pastes #26952 Raw Edit

:-)

public text v1 · immutable
#26952 ·published 2005-10-28 18:27 UTC
rendered paste body
function IsAvlTree(t:binarytree;i:integer):boolean;
//needs a counter to be passed in for balance check
begin
if (t = nil) then
begin
        result := false;
        exit;
end;

if  ((t.left = nil) AND  (t.right = nil)) then
        result := True
else if (t.right =nil) then
begin
        i := i+1;
        if ((i >1) OR (i < -1)) then  begin
                Result:= FALSE
                end
        else result := true and isavltree(t.left,i);
        end

else if (t.left = nil) then
begin
        i := i-1;
        if ((i >1) or (i < -1)) then
                result:= FALSE
        else result := true and isavltree(t.right,i);
        end

else
        result := isavltree(t.left,i) AND isavltree(t.right,i);
end;