Advertisement
Vasilena

PracticeDayThreeExercise3

Jul 8th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>;
  2.  
  3. void bubbleSort(int array[])
  4. {
  5.   for (int c = 0 ; c < sizeof(array) - 1; c++)
  6.   {
  7.     for (int d = 0 ; d < sizeof(array) - c - 1; d++)
  8.     {
  9.       if (array[d] > array[d+1])
  10.       {
  11.         int temp = array[d];
  12.         array[d] = array[d+1];
  13.         array[d+1] = temp;
  14.       }
  15.     }
  16.   }
  17.   Print(array);
  18. }
  19.  
  20. void Print(int array[]){
  21.     for (int c = 0; c < sizeof(array); c++)
  22.   {
  23.       printf("%d ", array[c]);
  24.   }
  25. }
  26.  
  27. int main()
  28. {
  29.   int array[9] = {3, 8, 15, 67, 2, 7, -6, -12, 0};
  30.   printf("Array before sorting:\n");
  31.   Print(array);
  32.   printf("\nArray after sorting:\n");
  33.   bubbleSort(array);
  34.   return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement