[此贴子已经被作者于2006-9-24 3:39:38编辑过]
function out0_2(T: bitreptr): boolean;
function out02 (T1,T2: bitreptr):boolean;
begin
if (T1=nil) and (T2=nil) then out02:=true
else if (T1=nil) or (T2=nil) then out02:=false
else out02:=out02(T1^.lchild,T1^.rchild) and
out02(T2^.lchild,T2^.rchild);
end;
begin
if T=nil then out0_2:=true
else begin
out0_2:=out02(T^.lchild,T^.rchild);
end;
end;
function high(T: bitreptr): integer;
function max(a,b:integer):integer;
begin
if a>b then max:=a
else max:=b;
end;
begin
if T=nil then high:=0
else
high:=max(high(T^.lchild),high(T^.rchild))+1;
end;
function LTallThanR(T: bitreptr): boolean;
begin
if T=nil then LTallThanR:=true
else
if (high(T^.lchild)>=high(T^.rchild)) and
(high(T^.lchild)<=high(T^.rchild)+1) then LTallThanR:=true
else LTallThanR:=false;
end;
好像没有错了,思路:二叉树的结点满足出度要么为0,要么为2,用function out0_2(T: bitreptr): boolean;来判断,还要满足相对于某个结点,右子树高度<=左子树高度<=右子树高度+1。用function LTallThanR(T: bitreptr): boolean;判断,当同时满足这两个条件时,就时完全二叉树。即out0_2(T) and LTallThanR(T)=true时就是完全二叉树。
'ABD##E##C##';
'Ab##c##';
'ABCD#####';
'ABD###C##';
'ABDH##I##E##CF##G##';
'AB##CD##E##';
[此贴子已经被作者于2006-9-23 10:31:11编辑过]