Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program selectionSort;
- uses crt;
- var
- arr: array[1..10] of integer;
- i, j, minIndex, temp: integer;
- begin
- clrscr;
- //mengisi array dengan data acak
- randomize;
- for i := 1 to 10 do
- arr[i] := random(100);
- //menampilkan data sebelum diurutkan
- writeln('Data sebelum diurutkan:');
- for i := 1 to 10 do
- write(arr[i], ' ');
- //algoritma selection sort
- for i := 1 to 9 do begin
- minIndex := i;
- for j := i + 1 to 10 do begin
- if (arr[j] < arr[minIndex]) then
- minIndex := j;
- end;
- temp := arr[i];
- arr[i] := arr[minIndex];
- arr[minIndex] := temp;
- end;
- //menampilkan data setelah diurutkan
- writeln;
- writeln('Data setelah diurutkan:');
- for i := 1 to 10 do
- write(arr[i], ' ');
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement