fork(2) download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. void bubbleSortM(int A[], int n) {
  5. for (int i = 1; i < n; i++) {
  6. bool troca = 0;
  7.  
  8. for (int j = n - 1; j >= i; j--) {
  9. if (A[j - 1] > A[j]) {
  10. int aux = A[j - 1];
  11. A[j - 1] = A[j];
  12. A[j] = aux;
  13. troca = 1;
  14. }
  15. }
  16. if (!troca) {
  17. return;
  18. }
  19. }
  20. }
  21.  
  22. void printVetor(int A[], int size) {
  23. for (int i = 0; i < size; i++) {
  24. printf("%d ", A[i]);
  25. }
  26. }
  27.  
  28. int main() {
  29. int A[] = {12, 11, 13, 5, 6, 7};
  30. int n = sizeof(A) / sizeof(A[0]);
  31. bubbleSortM(A, n);
  32. printf("Vetor ordenado: \n");
  33. printVetor(A, n);
  34. }
Success #stdin #stdout 0s 4300KB
stdin
Standard input is empty
stdout
Vetor ordenado: 
5 6 7 11 12 13