For sikli yordamida amalga oshirish mumkin. Elementni massiv boshiga (birinchi o’ringa) ko’chirish uchun prosedura


Download 36.98 Kb.
bet7/16
Sana01.04.2023
Hajmi36.98 Kb.
#1318578
1   2   3   4   5   6   7   8   9   10   ...   16
Bog'liq
masala 1

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.

Download 36.98 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   ...   16




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling