假设二叉树采用链接方式存储,编写一个对二叉树进行中序遍历的递归和非递归程序

来源:百度知道 编辑:UC知道 时间:2024/05/27 16:48:00
假设二叉树采用链接方式存储,编写一个对二叉树进行中序遍历的递归和非递归程序
假设二叉树采用链接方式存储,编写一个对二叉树进行后序遍历的递归和非递归程序

这是我做的。
中序遍历:
var root,i,t,tl,tr,n:byte;
depth,l,r:array[1..100]of byte;
procedure b(p:byte);
begin
if p=0 then exit;
b(l[p]);
writeln(p,' ');
b(r[p]);
end;
begin
readln(n);
for i:=1 to n do begin
readln(t,l[t],r[t]);
if l[t]>0 then inc(depth[l[t]]);
if r[t]>0 then inc(depth[r[t]]);
end;
for i:=1 to n do if depth[i]=0 then begin
root:=i;
break;
end;
b(root);
end.
后序遍历:
var root,i,t,tl,tr,n:byte;
depth,l,r:array[1..100]of byte;
procedure c(p:byte);
begin
if p=0 then exit;
c(l[p]);
c(r[p]);
writeln(p,' ');
end;
begin
readln(n);
for i:=1 to n do begin
readln(t,l[t],r[t]);
if l[t]>0 then inc(depth[l[t]]);
if r[t]>0 then inc(depth[r[t]]);
end;
for i:=1 to n do if depth[i]=0 then begin
root:=i;
break;
end;

假设二叉树采用链接方式存储,编写一个对二叉树进行中序遍历的递归和非递归程序 二叉树链接存储的问题? 采用二叉链表存储结构,按前根序输入二叉树的结点序列,建立二叉树并中根序遍历该二叉树,计算叶子节点的个数 数据结构编二叉树 sqlserver 存储二叉树 假设以二叉链表存储的二叉数中,每个结点所含数据结构元素均为单字母,试编写算法,按树状打印二叉树的算 设计一个算法把二叉数的叶子结点按从左到右的顺序连成一个单链表,二叉树按ldchild-rchild方式存储,? 已知用二叉链表存储二叉树,判断两棵二叉树是否相等 采用什么存储管理方式不会产生内部碎片? 设二叉树以二叉链表为存储结构,编写一个后续遍历二叉树的非递归算法