Advertisement
yeskendir_sultanov

Bubble Sort

Mar 28th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.     int a[n];
  9.     for (int i = 0; i < n; ++i) {
  10.         cin >> a[i];
  11.     }
  12.     for (int i = 0; i < n; ++i) {
  13.         for (int j = 0; j + 1 < n; ++j) {
  14.             if (a[j] > a[j + 1]) {
  15.                 swap(a[j], a[j + 1]);
  16.             }
  17.         }
  18.     }
  19.     return 0;
  20. }
  21. /*
  22. Time Complexity O(N^2)
  23. Memory Complexity O(1)
  24. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement