Cod sursa(job #1224231)

Utilizator vrabievictorvictor vrabie vrabievictor Data 30 august 2014 11:13:52
Problema Sortare prin comparare Scor 20
Compilator fpc Status done
Runda Arhiva educationala Marime 0.89 kb
program arb_cautare;
type arb=^nod;
nod=record
info:integer;
st,dt:arb;
end;
var i,n,x:longint; a,b,c:arb;ok:boolean;
procedure insert(x:longint);
begin
if a=nil then
begin
new(a);a^.info:=x;a^.st:=nil;a^.dt:=nil;
end else
begin
new(b);b:=a;
ok:=true;
while ok do
begin
if (x>b^.info)and(b^.dt<>nil)  then b:=b^.dt else
if (x<=b^.info)and(b^.st<>nil) then b:=b^.st else
if  (x<=b^.info) then
begin
new(c);c^.info:=x;c^.st:=nil;c^.dt:=nil;
b^.st:=c;ok:=false;
end else
begin
new(c);c^.info:=x;c^.st:=nil;c^.dt:=nil;
b^.dt:=c; ok:=false;
end;
end;
end;
end;
procedure scrie(a:arb);
begin
if a<>nil then
begin
scrie(a^.st);write(a^.info,' ');scrie(a^.dt);
end;
end;

begin
assign(input,'algsort.in');reset(input);
readln(n);
for i:=1 to n do
begin
read(x);
insert(x);
end;
assign(output,'algsort.out');rewrite(output);
scrie(a);
close(input);close(output);
end.