Pagini recente » Cod sursa (job #1182444) | Cod sursa (job #2749063) | Cod sursa (job #351729) | Cod sursa (job #862808) | Cod sursa (job #258091)
Cod sursa(job #258091)
type pnod=^nod;
nod= record
c:longint;
info:int64;
st,dr:pnod;
end;
var p:pnod;
n,i:longint;
x:int64;
f,g:text;
procedure init(var p:pnod);
var q:pnod;
begin
new(q);q^.info:=x;q^.c:=1;
q^.st:=nil;q^.dr:=nil;
p:=q;
end;
procedure caut(p:pnod);
begin
if x=p^.info then inc(p^.c)
else if x<p^.info then begin
if p^.st<>nil then caut(p^.st)
else init(p^.st);
end
else begin
if p^.dr<>nil then caut(p^.dr)
else init(p^.dr);
end;
end;
procedure afisare(p:pnod);
begin
if p<>nil then begin
afisare(p^.st);
for i:=1 to p^.c do write(g,p^.info,' ');
afisare(p^.dr);
end;
end;
begin
assign(f,'algsort.in');reset(f);
assign(g,'algsort.out');rewrite(g);
readln(f,n);
read(f,x);init(p);
for i:=1 to n-1 do begin
read(f,x);
caut(p);
end;
afisare(p);
close(g);
end.