Advertisement
Vladpepe

Untitled

Jun 10th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "stdio.h"
  3. #include "stdbool.h"
  4.  
  5. #define swap(type, i, j) {type t = i; i = j; j = t;}
  6.  
  7. void BubbleSort(int v[], int dim) {
  8.     int i;
  9.     bool ordinato = false;
  10.     while (dim>1 && !ordinato) {
  11.         ordinato = true; /* hp: รจ ordinato */
  12.         for (i = 0; i<dim - 1; i++)
  13.             if (v[i]>v[i + 1]) {
  14.                
  15.                 swap(int, v[i], v[i + 1]);
  16.                
  17.                 ordinato = false;
  18.             }
  19.         dim--;
  20.     }
  21. }
  22.  
  23.  
  24. int main() {
  25.  
  26.     int array[10] = { 9,3,6,7,5,4,3,2,5,11 };
  27.  
  28.  
  29.     BubbleSort(array, 10);
  30.  
  31.     for (int i = 0; i < 10;i++)
  32.     {
  33.         printf("%d", array[i]);
  34.  
  35.     }
  36.     return 0;
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement