Advertisement
Md_hosen_zisad

insertion

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