fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // This function implements the bubbleSort algorithm.
  6. void sort(char arr[])
  7. {
  8. bool flag;
  9. char temp;
  10. do {
  11. flag = false;
  12. for (int i = 0; i < 8; i++)
  13. if (arr[i] > arr[i + 1]) {
  14. flag = true;
  15. temp = arr[i];
  16. arr[i] = arr[i + 1];
  17. arr[i + 1] = temp;
  18. }
  19. } while(flag);
  20. }
  21.  
  22. int main()
  23. {
  24. char arr[9];
  25.  
  26. // Prompt the user for input.
  27. cout << "Input 9 letters: ";
  28. for (int i = 0; i < 9; i++)
  29. cin >> arr[i];
  30.  
  31. // Sort the array in alphabetical order.
  32. sort(arr);
  33.  
  34. // Display the array.
  35. for (int i = 0; i < 9; i++)
  36. cout << arr[i] << " ";
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.02s 2684KB
stdin
Standard input is empty
stdout
Input 9 letters: � � � � � � �  y