Program L195;
uses Crt;
const
n = 20; k = 10;
type
t = array[1..n + k] of integer;
var
b : array[1..k] of integer;
a : t;
i, j, p : integer;
{----------------------------------------------------------------------------------------}
Procedure quick_search(a : t; n, b : integer; var p : integer);
var
q, s : integer;
begin
p := 1; q := n +1;
while p < q do
begin
s := (p + q) div 2;
if a[s] < b then p := s + 1 else q := s
end
end;
{----------------------------------------------------------------------------------------}
begin
writeln('O’sish bo’yicha tartiblangan massivni kiriting');
randomize;
for i := 1 to n do
begin
write(i, 'chi elementni kiriting'); readln(a[i])
end;
writeln('Berilgan tartiblangan massiv');
for i := 1 to n do write(a[i], ' ');
writeln;
writeln('Brinchi massivga joylashtirish uchun massiv');
for i := 1 to k do
begin
b[i] := random(101);
write(b[i], ' ')
end;
writeln;
for i := 1 to k do
begin
quick_search(a, n + i - 1, b[i], p);
for j := n + i downto p + 1 do a[j] := a[j - 1];
a[p] := b[i];
end;
writeln('Yangi massiv');
for i := 1 to n + k do write(a[i], ' ');
writeln
end.
196-misol. Chap tomonida o’zidan kichik elementlar, o’ng tomonda esa o’zidan kattalari joylashgan “o’rta” elementni topish dasturini tuzing. (Elementlarning o’rnini almashtirish prosedurasi va “o’rta” elementni aniqlash prosedurasidan foydalaning).
Prosedurani middle deb ataymiz (middle ning inglizchadan tarjimasi - o’rta).
Asosiy dasturdagi massivni x deb belgilaymiz.
Do'stlaringiz bilan baham: |