Pagini recente » Cod sursa (job #944945) | Rating Rotaru Ioan (Ioannnnnnnnnnn) | Cod sursa (job #1839239) | Cod sursa (job #1277253) | Cod sursa (job #425949)
Cod sursa(job #425949)
program nums;
type Arbore=^Nod;
Nod=record
info:ansistring;
st,dr:Arbore;
end;
var r:arbore;
f,g:text;
t,i,n,k,poz:longint;
x:ansistring;
c:char;
Function XMaiMic(x,y:ansistring):boolean;
var i:longint;
code,intx,inty:integer;
begin
XMaiMic:=false;
If length(x)<length(y) then XMaiMic:=true
else
If length(x)=length(y)then
For i:=1 to length(x) do
begin
val(x[i],intx,code);
val(y[i],inty,code);
If intx<inty then
begin
XMaiMic:=true;
break;
end;
end;
end;
Function XMaiMare(x,y:ansistring):boolean;
var i:longint;
code,intx,inty:integer;
begin
XMaiMare:=false;
If length(x)>length(y) then XMaiMare:=true
else
If length(x)=length(y)then
For i:=1 to length(x) do
begin
val(x[i],intx,code);
val(y[i],inty,code);
If intx>inty then
begin
XMaiMare:=true;
break;
end;
end;
end;
Procedure InsereazaNod(Var p:arbore;x:ansistring);
begin
If p<>nil then
begin
If XMaiMic(x,p^.info) then
InsereazaNod(p^.st,x)
else
If XMaiMare(x,p^.info) then
InsereazaNod(p^.dr,x)
end
else
begin
new(p);
p^.info:=x;
p^.st:=nil;
p^.dr:=nil;
end;
end;
Procedure SRD(p:arbore);
begin
If p<>nil then
begin
SRD(p^.st);
k:=k+1;
If k=poz then writeln(g,p^.info);
SRD(p^.dr);
end;
end;
begin
r:=nil;
assign(f,'3-nums.in');
assign(g,'nums.out');
rewrite(g);
reset(f);
readln(f,n);
For i:=1 to n do
begin
read(f,t);
If t=1 then
begin
read(f,c);
read(f,x);
end
else readln(f,poz);
If t=1 then InsereazaNod(r,x)
else
begin
k:=0;
SRD(r);
end;
end;
close(g);
close(f);
end.