Selection Sort Program using C Language
Selection Sort Algorithm
Selection Sort Algorithm |
Selection Sort Program
//selection sort
#include<stdio.h>
int main()
{
int a[10],n,i,imin,j,temp;
scanf("%d",&n); //takes the limit from user
for(i=0;i<n;i++)
//takes the elements for array
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
imin=i;
for(j=i+1;j<n;j++)
{
if(a[j]<a[imin])
imin=j;
}
temp=a[i];
a[i]=a[imin];
a[imin]=temp;
}
for(i=0;i<n;i++)
printf("%d\t",a[i]);
return 0;
}
Selection Sort Time Complexity
O(n2)
0 comments:
Post a Comment