📄 tree.pas
字号:
program test;
type
pot=^rec;
rec=record
d:char;
l,r:pot;
end;
var
h:pot;
procedure init;
var
a:array[1..100] of pot;
ch:char;
i,k,t:integer;
p:pot;
begin
read(ch);
i:=0;
t:=0;
while ch<>'@' do
begin
case ch of
'a'..'z':begin
new(p); p^.d:=ch; p^.l:=nil; p^.r:=nil;
if i<>0 then
case k of
1:a[i]^.l:=p;
2:a[i]^.r:=p;
end;
end;
'(':begin
i:=i+1; a[i]:=p; k:=2;
if i>t then t:=i;
end;
')':i:=i-1;
',':k:=1;
end;
read(ch);
end;
h:=a[1];
writeln(t+1);
end;
procedure print(p:pot);
begin
write(p^.d,' ');
if p^.l<>nil then print(p^.l);
if p^.r<>nil then print(p^.r);
end;
procedure print1(p:pot);
begin
if p^.l<>nil then print1(p^.l);
write(p^.d,' ');
if p^.r<>nil then print1(p^.r);
end;
procedure print2(p:pot);
begin
if p^.l<>nil then print2(p^.l);
if p^.r<>nil then print2(p^.r);
write(p^.d,' ');
end;
begin
init;
print(h);
writeln;
print1(h);
writeln;
print2(h);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -