Advertisement
Md_hosen_zisad

selection sort

Mar 18th, 2018
385
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=0;i<=n-1;i++)
  15.     {
  16.         for(j=i+1;j<=n-1;j++)
  17.         {
  18.             if(ar[i]>ar[j])
  19.             {
  20.                 swap(ar[i],ar[j]);
  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