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


var x : t; m, i : integer; {---------------------------------------------------------------------------------------} Procedure


Download 36.98 Kb.
bet9/16
Sana01.04.2023
Hajmi36.98 Kb.
#1318578
1   ...   5   6   7   8   9   10   11   12   ...   16
Bog'liq
masala 1

var
x : t;
m, i : integer;
{---------------------------------------------------------------------------------------}
Procedure create(n : integer; var x : t);
var
i : integer;
begin
randomize;
writeln('Berilgan butun sonli massiv’);
 for i := 1 to do
 begin
x[i] := random(201)-100;
write(x[i], ' ')
end;
writeln
end;
{----------------------------------------------------------------------------------------}
Procedure exchange(l, r : integer);
var
p : integer;
 begin
p := x[l]; x[l] := x[r]; x[r] := p
end;
{----------------------------------------------------------------------------------------}
Procedure middle(k : integer; var x : t; var m : integer);
var
l, r : integer;
 begin
l := 1; r := k;
 repeat
 while (x[l] <= x[r]) and (l < r) do r := r - 1;
exchange(l, r); {Almashtirish prosedurasi}
while (x[l] <= x[r]) and (l < r) do l := l + 1;
exchange(l, r)
until l = r;
m := l
end;
{---------------------------------------------------------------------------------------}
 begin
create(n, x);
middle(n, x, m);
write('O’rta elementli o’zgartirilgan massiv', x[m]);
writeln(m, 'chi o’rinda');
for i := 1 to n do write(x[i], ' ');
writeln
end.
Bu dasturni bir necha marta bajarib ko’ring va “o’rta” elementning massivdagi joylashishga e’tibor bering. Siz shunga e’tibor berishingiz kerakki, har doim ham (aniqrog’i, kamdan-kam hollarda) “o’rta” element massivdagi haqiqiy o’rta joyni egallayvermaydi, lekin bu uning tezkorligiga hech qanday ta’sir qilmaydi.

Download 36.98 Kb.

Do'stlaringiz bilan baham:
1   ...   5   6   7   8   9   10   11   12   ...   16




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