fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n = 5;
  7. int a[n] = {4, 3, 5, 1, 2};
  8. int t, i, j, k;
  9.  
  10. for (i = 1; i < n; i++){
  11. for (k = 0; k < n; k++)
  12. cout << endl;
  13.  
  14. for (j = 0; j < i - n; j++) {
  15. if (a[j] > a[j+1]) {
  16. t = a[j];
  17. a[j] = a[j+1];
  18. a[j+1] = t;
  19. }
  20. }
  21. }
  22.  
  23. cout << "排序好的陣列為" << endl;
  24. for (i = 0; i < n; i++)
  25. cout << a[i] << " ";
  26. return 0;
  27. }
Success #stdin #stdout 0s 5692KB
stdin
Standard input is empty
stdout



















排序好的陣列為
4 3 5 1 2