Tree 在Ada中寻找二叉树中的叶子
我已经用Ada写了BSt,我正在试着打印叶子。下面是树和节点代码Tree 在Ada中寻找二叉树中的叶子,tree,binary-search-tree,ada,Tree,Binary Search Tree,Ada,我已经用Ada写了BSt,我正在试着打印叶子。下面是树和节点代码 type Node; type Tree is access Node; type Node is record Item: Integer; Left,Right: Tree; end record; 我可以检查Tree是否为null,但如果我检查Tree.Left或Tree.Right是否为null,我将得到 raised CONSTRAINT_ERROR : access check failed 与…一致
type Node;
type Tree is access Node;
type Node is record
Item: Integer;
Left,Right: Tree;
end record;
我可以检查Tree是否为null,但如果我检查Tree.Left或Tree.Right是否为null,我将得到
raised CONSTRAINT_ERROR : access check failed
与…一致
if (T.Left/=null) then
如何检查节点是否没有子节点?这可能是因为
T
istelf是null
,并且有一个叶子试试看
如果T/=null,则
如果T.left=null,T.right=null,则
--叶节点 如果
T
为null
,则它什么都不是!我认为最好避免使用空指针进行递归调用。假设你是用递归来做的?啊,是的。T
的父项将是一片叶子,而不是T
。适合我在精神上对半个书面句子进行修改…呃,可能是一片叶子-只有当左
和右
都是空
。