Advertisement
bolji_programer

Algoritmi za sortiranje - Bubble sort

Jan 1st, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin>>n;
  9.  
  10.     int A[n];
  11.  
  12.     for (int i=0;i<n;i++)
  13.         cin>>A[i];
  14.  
  15.     for (int i=0;i<n-1;i++)
  16.     {
  17.         for (int j=0;j<n-i-1;j++)
  18.         {
  19.             if (A[j]>A[j+1]) swap(A[j],A[j+1]);
  20.         }
  21.     }
  22.  
  23.     for (int i=0;i<n;i++)
  24.         cout<<A[i]<<' ';
  25.     cout<<endl;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement