Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program bubbleSort;
- uses crt;
- var
- arr: array[1..10] of integer;
- i, j, 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 bubble sort
- for i := 1 to 9 do begin
- for j := 1 to 10-i do begin
- if (arr[j] > arr[j + 1]) then
- begin
- temp := arr[j];
- arr[j] := arr[j + 1];
- arr[j + 1] := temp;
- end;
- end;
- 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