Jumat, 13 Juli 2012

Algoritma Sorting

program sorting; 02.var x : array[1..100] of integer; 03.i, n, min, kelompok, temp, tempatnya_min : integer; 04.begin 05.{ membuat data array yang terdiri dari data : 3 9 1 4 0 2 } 06. 07.x[1] := 3; 08.x[2] := 9; 09.x[3] := 1; 10.x[4] := 4; 11.x[5] := 0; 12.x[6] := 2; 13. 14.n := 6; {jumlah data} 15. 16.{ proses sorting ascending } 17. 18.for kelompok := 1 to n do 19.begin 20.min := x[kelompok]; 21.for i := kelompok to n do 22.begin 23.if (x[i] <= min) then 24.begin 25.min := x[i]; 26.tempatnya_min := i; 27.end; 28.end; 29. 30.temp := x[kelompok]; 31.x[kelompok] := x[tempatnya_min]; 32.x[tempatnya_min] := temp; 33.end; 34. 35.{ menampilkan hasil sorting } 36. 37.for i:=1 to n do 38.begin 39.writeln(x[i], ' '); 40.end; 41.end.

Tidak ada komentar:

Posting Komentar