{二叉树排序}
type tree=^node;
node=record
data:integer;
lch,rch:tree;
end;
var root:tree; f:text;
procedure stree(var root:tree);
var p,t:tree;k:integer;
begin
read(f,k);
new(root);
root^.data:=k;root^.lch:=nil;root^.rch:=nil;
while not eof(f) do begin
read(f,k);
p:=root;
repeat
t:=p;
if k<p^.data then p:=p^.lch else p:=p^.rch;
until p=nil;
new(p);
p^.data:=k;p^.lch:=nil;p^.rch:=nil;
if k<t^.data then t^.lch:=p else t^.rch:=p;
end;
end;
procedure inorder(root:tree);
begin
if root<>nil then begin
inorder(root^.lch);
write(f,root^.data:5);
inorder(root^.rch);
end;
end;
begin
assign(f,'stree.in');
reset(f);
stree(root);
close(f);
assign(f,'stree.out');
rewrite(f);
inorder(root);
close(f);
end.
type tree=^node;
node=record
data:integer;
lch,rch:tree;
end;
var root:tree; f:text;
procedure stree(var root:tree);
var p,t:tree;k:integer;
begin
read(f,k);
new(root);
root^.data:=k;root^.lch:=nil;root^.rch:=nil;
while not eof(f) do begin
read(f,k);
p:=root;
repeat
t:=p;
if k<p^.data then p:=p^.lch else p:=p^.rch;
until p=nil;
new(p);
p^.data:=k;p^.lch:=nil;p^.rch:=nil;
if k<t^.data then t^.lch:=p else t^.rch:=p;
end;
end;
procedure inorder(root:tree);
begin
if root<>nil then begin
inorder(root^.lch);
write(f,root^.data:5);
inorder(root^.rch);
end;
end;
begin
assign(f,'stree.in');
reset(f);
stree(root);
close(f);
assign(f,'stree.out');
rewrite(f);
inorder(root);
close(f);
end.