fork download
  1. #include <iostream>
  2.  
  3. void print(int a[], int n){
  4. for (int i = 0; i < n; i++)
  5. std::cout << a[i] << " ";
  6. std::cout << "\n";
  7. }
  8.  
  9. void bubbleSort(int x[], int n){
  10. for(int i = 1; i < n; i++){
  11. for (int j=n-1; j >= i; j--)
  12. if (x[j] < x[j-1])
  13. std::swap(x[j], x[j-1]);
  14. print(x,n);
  15. }
  16. }
  17.  
  18.  
  19.  
  20. int main() {
  21. int x[] = {32, 99, 77, 2, 87, 24, 16, 94, 28, 33};
  22. bubbleSort(x,10);
  23. return 0;
  24. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
2 32 99 77 16 87 24 28 94 33 
2 16 32 99 77 24 87 28 33 94 
2 16 24 32 99 77 28 87 33 94 
2 16 24 28 32 99 77 33 87 94 
2 16 24 28 32 33 99 77 87 94 
2 16 24 28 32 33 77 99 87 94 
2 16 24 28 32 33 77 87 99 94 
2 16 24 28 32 33 77 87 94 99 
2 16 24 28 32 33 77 87 94 99