var a:array[1..40] of integer; i,b,c,e,n,r,l,m,k,x:integer; begin n:=40; randomize; for i:=1 to n do a[i]:=random(900)+100; for i:=1 to n do write(a[i]:3,' '); writeln; i:=2; repeat b:=1; e:=i-1; c:=trunc((b+e)/2); while b<>c do begin if (a[c] div 100)>(a[i] div 100) then e:=c else b:=c; c:=trunc((b+e)/2); end; if a[b]<a[i] then begin if (a[i] div 100)>(a[e] div 100) then b:=e+1 else b:=e; end; k:=i; x:=a[i]; while k>b do begin a[k]:=a[k-1]; k:=k-1 end; a[b]:=x; i:=i+1; until not(i<=n); writeln('out'); for i:=1 to n do write(a[i]:3,' '); writeln; readln; end. |