728x90 AdSpace

Latest News

Tuesday 16 September 2014

Selection Sort Program using C Language

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

Selection Sort Program using C Language
  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Top