二叉树广义表
type
pointer=^node;
node=record
da
left,right:pointer;
end;
var s:array[1..200] of pointer;
head,p:pointer;
k,top:integer;
ch:char;
procedure print(p:pointer);
begin
write(p^.da
if p^.left<>nil then print(p^.left);
if p^.right<>nil then print(p^.right);
end;
begin
read(ch);
head:=nil;
while ch<>'@' do
begin
case ch of
'A'..'Z':
begin
new(p);
p^.da
p^.left:=nil;
p^.right:=nil;
if head=nil then
head:=p
else
case k of
1:s[top]^.left:=p;
2:s[top]^.right:=p;
end;
end;
'(':
begin
top:=top+1;
s[top]:=p;
k:=1;
end;
')':top:=top-1;
',':k:=2;
end;
read(ch);
end;
print(head);
writeln;
end.