Header Ads

Learn Together, Stay Connected.

Selection Sort

 

#include<bits/stdc++.h>
using namespace std;

int main()
{
ios_base :: sync_with_stdio(0),cin.tie(0);
// freopen("in.txt","r",stdin);

int x;
int count[202];
int n;
cin>>n;
int key;
for(int i=0;i<n;i++)
{
cin>>count[i];
}
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(count[i]>count[j])
{
int temp=count[i];
count[i]=count[j];
count[j]=temp;
}
}

}
for(int i=0;i<n;i++)
{
cout<<count[i]<<" ";
}
cout<<endl;

return 0;
}

No comments

Theme images by Dizzo. Powered by Blogger.