7.14-rasm. Massivni tartiblash dasturining dialog oynasi
7.9-listing. Massivni oddiy usul bilan tartiblash
procedure TForm1.Button1Click(Sender: TObject);
const n=10; // massiv o`lchami
var i,k,l: word;
ind: word; // k-chidan keyingi eng kichik element indeksi
c: integer; // elementlar o`rin almashganda yordam beradi
min:integer; // k-chi haddan boshlab, eng kichik element
a:array[1..n] of integer;
begin
s : '';
for i : 1 to n do
a[i] : strtoint(stringgrid1.Cells[i-1,0]);
for k : 1 to n-1 do begin
min : a[k]; ind : k;
k-chi xaddan boshlab, eng kichik element topilmoqda
for l : k1 to n do
if min>a[l] then begin min : a[l]; ind : l; end;
eng kichik va tartiblanayotgan elementlar o`rin almashadi
c : a[ind]; a[ind] : a[k]; a[k] : c;
natijalarni chiqarish uchun yig’ib borilmoqda
s : s inttostr(a[k]) ' ';
end;
oxirgi element natijaga chiqarish uchun olinmoqda
s : s inttostr(a[n]);
label1.Caption : s;
end;
Do'stlaringiz bilan baham: |