Advertisement
mfrankic

B

Apr 20th, 2019
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #ifndef DEBUG
  4. #define DEBUG(...) printf(__VA_ARGS__)
  5. #endif
  6.  
  7. #define SIZE 512
  8.  
  9. // Implementirati funkciju za bubble sort
  10. void bubble_sort(int n, int array[]) {
  11.   for (int i = 0; i < n; ++i)
  12.   {
  13.     for (int j = 1; j < n; ++j)
  14.     {
  15.       if(array[j - 1] < array[j]){
  16.         int tmp = array[j - 1];
  17.         array[j - 1] = array[j];
  18.         array[j] = tmp;
  19.       }
  20.     }
  21.   }
  22. }
  23.  
  24. int main() {
  25.   int n, array[SIZE];
  26.  
  27.   scanf("%d", &n);
  28.   for (int i = 0; i < n; i++) {
  29.     scanf("%d", &array[i]);
  30.   }
  31.  
  32.   // Dodati poziv funkcije za sortiranje
  33.   bubble_sort(n, array);
  34.  
  35.   for (int i = 0; i < n; i++) {
  36.     printf("%d ", array[i]);
  37.   }
  38.  
  39.   return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement