Advertisement
genium08

Buble_sort(from heavy to light)

Feb 27th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void buble_sort(int arr[], int n) {
  5.     for(int i = 0; i < n; i++) {
  6.         for(int j = 0; j < n - i - 1; j++) {
  7.             if(arr[j] < arr[j + 1]) {
  8.                 swap(arr[j], arr[j + 1]);
  9.             }
  10.         }
  11.     }
  12. }
  13.  
  14. int main()
  15. {
  16.     int array_to_sort[15] = {4, 30, 79, 11, 40, 52, 93, 13, 97, 80, 44, 50, 31, 44, 19};
  17.     buble_sort(array_to_sort, 15);
  18.     for(int x : array_to_sort) {
  19.         cout << x << " ";
  20.     }
  21.     return 0;
  22. }
  23. /* 97 93 80 79 52 50 44 44 40 31 30 19 13 11 4 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement