Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program BubbleSortChar;
- uses crt;
- var
- str: string;
- n, i, j: Integer;
- temp: Char;
- begin
- clrscr;
- // input string yang akan diurutkan
- write('Masukkan string: ');
- readln(str);
- // hitung panjang string
- n := Length(str);
- // lakukan bubble sort
- for i := 1 to n-1 do
- begin
- for j := 1 to n-i do
- begin
- if str[j] > str[j+1] then
- begin
- temp := str[j];
- str[j] := str[j+1];
- str[j+1] := temp;
- end;
- end;
- end;
- // tampilkan string setelah diurutkan
- writeln('Setelah diurutkan:');
- writeln(str);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement