Selection Sort

C Programming

Selection sort is a sorting algorithm, specifically an in-place comparison sort. Selection sort is noted for its simplicity, and also has performance advantages over more complicated algorithms in certain situations.

Language : C

[sourcecode language='c']
//Selection Sort
#include
void main()
{
int a[100],small,p,temp,j,i,n;

printf(“Enter the value for n :”);
scanf(“%d”, &n);

for(i=0;i { printf(“Enter the value for the %d element :”, i+1);
scanf(“%d”, &a[i]);
}

for(i=0;i { small=a[i];
p=i;

for(j=i+1;j {
if(a[j] {
small=a[j];
p=j;
}
}

temp=a[i];
a[i]=a[p];
a[p]=temp;
}

printf(“The sorted array is : “);

for(i=0;i printf(“\n%d”, a[i]);

}
[/sourcecode]



Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.


WordPress - Vaibhav Kanwal