Advertisement
Md_hosen_zisad

swap binary search

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