SELECTION SORT
#include<iostream>
using namespace std;
void sort(int a[5])
{
int i,j;
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[i]>a[j])
{
swap(a[i],a[j]);
}
}
}
cout<<"\nSorted
array";
for(i=0;i<5;i++)
{
cout<<"\n"<<a[i];
}
}
void swap(int &i,int &j)
{
i=i+j;
j=i-j;
i=i-j;
}
int main()
{
int a[5],i;
cout<<"\nEnter
elements of array";
for(i=0;i<5;i++)
{
cin>>a[i];
}
sort(a);
}
OUTPUT
No comments:
Post a Comment