这个二叉树的程序
在运的时候无论怎么改都是106号错误
const m=200;
type
node=record
data: char;
prt,lch,rch:integer;
end;
treetype=array[1..m] of node;
var tree:treetype;
n,i,j,p:integer;
procedure preorder(i:integer);
begin
if i<>0 then
begin
write(tree[i].data);
preorder(tree[i].lch);
preorder(tree[i].rch);
end;
end;
procedure inorder(i:integer);
begin
if i<>0 then
begin
inorder(tree[i].lch);
write(tree[i].data);
inorder(tree[i].rch);
end;
end;
begin
assign(input,'work1.in'); reset(input) ;
assign(output,'work1.out'); rewrite(output);
fillchar(tree,sizeof(tree),0);
read(n);
for i:= 1 to n do
begin
read(tree[i].data);
read(j); {就是这里}
if j<>0 then
begin
tree[i].lch:= j;
tree[j].prt:=i;
p:=j;
repeat
read(j);
if j<>0 then begin
tree[p].rch:=j;
tree[j].prt:=p;
p:=j;
end;
until j=0;
end;
writeln;
end;
preorder(1);
writeln;
inorder(1);
close(input);
close(output);
end.
在运的时候无论怎么改都是106号错误
const m=200;
type
node=record
data: char;
prt,lch,rch:integer;
end;
treetype=array[1..m] of node;
var tree:treetype;
n,i,j,p:integer;
procedure preorder(i:integer);
begin
if i<>0 then
begin
write(tree[i].data);
preorder(tree[i].lch);
preorder(tree[i].rch);
end;
end;
procedure inorder(i:integer);
begin
if i<>0 then
begin
inorder(tree[i].lch);
write(tree[i].data);
inorder(tree[i].rch);
end;
end;
begin
assign(input,'work1.in'); reset(input) ;
assign(output,'work1.out'); rewrite(output);
fillchar(tree,sizeof(tree),0);
read(n);
for i:= 1 to n do
begin
read(tree[i].data);
read(j); {就是这里}
if j<>0 then
begin
tree[i].lch:= j;
tree[j].prt:=i;
p:=j;
repeat
read(j);
if j<>0 then begin
tree[p].rch:=j;
tree[j].prt:=p;
p:=j;
end;
until j=0;
end;
writeln;
end;
preorder(1);
writeln;
inorder(1);
close(input);
close(output);
end.