Selection Sort
Write a program to perform selection sort.
/* Program to perform selection short. */
/* In this selection sort the element will be sort in descending order. */
#include<stdio.h>
#include<conio.h>
void ss(int[], int);
main()
{
/*here ne means number of elemnts in array.*/
/*here a means array.*/
/*here ss means selection sort. */
int a[50],ne,i;
printf ("Enter how many elements you wants to perform selection sort = ");
scanf("%d",&ne);
printf ("Enter the elements in array :-\n");
for (i=0;i<ne;i++)
{
scanf ("%d",&a[i]);
}
ss(a,ne);
printf ("Elements after sort :-\n");
for (i=0;i<ne;i++)
{
printf("%d\t",a[i]);
}
}
void ss (int a[], int ne)
{
/*Here temp means temporary for story data for temporarily. */
int pass, element, temp;
for (pass=0;pass<ne;pass++)
{
for (element=pass+1;element<ne;element++)
{
if (a[pass] > a[element])
{
temp=a[pass];
a[pass]=a[element];
a[element]=temp;
}
}
}
}
0 Comments
Thank You ! For your love