【提问pascal】 本渣渣写了一段建立二叉排序树的程序问题求教
pascal吧
全部回复
仅看楼主
level 7
pascal学员 楼主
type
nade=^tree;
tree=record
s:longint;
l,r:nade;
end;
var
shu:nade;
n,i:longint;
a:array [1..100] of longint;
procedure ins(x:longint;shu1:nade);
begin
if shu1=nil then
begin
new(shu1);
shu1^.s:=x;
end else
begin
if x<=shu^.s then ins(x,shu1^.l) else
if x>shu^.s then ins(x,shu1^.r);
end;
end;
procedure print(shu1:nade);
begin
if shu1=nil then exit;
print(shu1^.l);
write(shu1^.s,' ');
print(shu1^.r);
end;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]);
ins(a[i],shu);
end;
print(shu);
readln;readln;
end.
问题出在哪里了我检查了好多遍。。
2013年11月07日 02点11分 1
level 3
type
nade=^tree;
tree=record
s:longint;
l,r:nade;
end;
var
shu:nade;
n,i:longint;
a:array [1..100] of longint;
procedure ins(x:longint;var shu1:nade);
begin
if shu1=nil then
begin
new(shu1);
shu1^.r:=nil;
shu1^.l:=nil;
shu1^.s:=x;
end
else
begin
if x<=shu1^.s then ins(x,shu1^.l) else
if x>shu1^.s then ins(x,shu1^.r);
end;
end;
procedure print(shu1:nade);
begin
if shu1=nil then exit;
print(shu1^.l);
write(shu1^.s,' ');
print(shu1^.r);
end;
begin
readln(n);
for i:=1 to n do
begin
read(a[i]);
ins(a[i],shu);
end;
print(shu);
end.
2019年04月08日 07点04分 2
1