Advertisement
rayhanf

sort_char

Jun 9th, 2023
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.55 KB | Source Code | 0 0
  1. program BubbleSortChar;
  2. uses crt;
  3.  
  4. var
  5.     str: string;
  6.     n, i, j: Integer;
  7.     temp: Char;
  8.  
  9. begin
  10.     clrscr;
  11.     // input string yang akan diurutkan
  12.     write('Masukkan string: ');
  13.     readln(str);
  14.  
  15.     // hitung panjang string
  16.     n := Length(str);
  17.  
  18.     // lakukan bubble sort
  19.     for i := 1 to n-1 do
  20.     begin
  21.         for j := 1 to n-i do
  22.         begin
  23.             if str[j] > str[j+1] then
  24.             begin
  25.                 temp := str[j];
  26.                 str[j] := str[j+1];
  27.                 str[j+1] := temp;
  28.             end;
  29.         end;
  30.     end;
  31.  
  32.     // tampilkan string setelah diurutkan
  33.     writeln('Setelah diurutkan:');
  34.     writeln(str);
  35. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement