М | toto, ник Hunter ничего не напоминает? volvo |
М | toto, ник Hunter ничего не напоминает? volvo |
function Leaves(t: ttree): integer;
const max_nodes = 100;
var
st: array[1 .. max_nodes] of ttree;
sp, counter: integer;
begin
sp := 0; counter := 0;
repeat
while t <> nil do begin
inc(sp); st[sp] := t;
t := t^.left;
end;
if sp = 0 then begin
Leaves := counter; exit;
end;
t := st[sp]; dec(sp);
if (T^.right = nil) and (T^.left = nil)
then inc(counter);
t := t^.right;
until false;
end;