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;