a massivni ko’rib chiqishda davom etamiz, uchinchi element olinadi, a[3]=-77 va b massivning birinchi elementi bilan solishtiriladi:
a[3] < b[1], (-77 < -96),
shart bajarilmayapti, demak c massivning keyingi, uchinchi elementiga b massivning 1 qiymati beriladi:
c[3] := b[1], c[3] := -96.
Bu jarayon a yoki b massivning biron birida elementlar tugab qolmagunicha davom etadi (shuni qayd etish kerakki, a massivning elementlar soni b massivdagi elementlar soniga qaraganda kam bo’lishi, a massiv tezroq ko’rib chiqilar ekan-da degan fikrga olib kelishi kerak emas, chunki teskari holat tug’ilishi, ya’ni agar b massivning elementlari a massivdagi elementlardan kichik bo’lsa, u holda b massiv tezroq ko’rib chiqilishi mumkin).
Program L222;
uses Crt;
const
n = 10; m =15;
type
t = array[1..n] of integer;
u = array[1..m] of integer;
f = array[1..n+m] of integer;
var
a : t; b : u; c : f;
i, p, q : integer;
{----------------------------------------------------------------------------------------}
Procedure fast(q, p : integer; var a : t);
var
s, l, r : integer;
begin
l := q;
r := p;
s := a[l];
repeat
while (a[r] >= s) and (l < r) do r := r - 1;
a[l] := a[r];
while (a[l] <= s) and (l < r) do l := l + 1;
a[r] := a[l]
until l = r;
a[l] := s;
if q < l - 1 then fast(q, l - 1, a);
if l + 1 < p then fast(l + 1, p, a)
end;
{----------------------------------------------------------------------------------------}
Procedure fast1(q, p : integer; var b : u);
var
s, l, r : integer;
Do'stlaringiz bilan baham: |