Your Ad Here

Monday, February 25, 2008

Simple Selection Sort

#include< stdio.h>
#include< conio.h>

void simplesel(int a[],int b[],int n)
{
int j,i=0,k,H;
int L=32760;
k=0;
L=H;
while(i< n)
{
for(j=0;j< n;j++)
{
if(a[j]< L)
{
L = a[j];
k = j;
}
}
a[k] = H;
b[i] = L;
L = H;
i++;
}
}

main()
{
int a[10],b[10],i,n;
clrscr();

printf("Enter The number Of Elements\t: ");
scanf("%d",&n);
for(i=0;i< n;i++)
{
printf("\nElement %d\t: ",i+1);
scanf("%d",&a[i]);
}

printf("\nArray Befor Sorting : ");
for(i=0;i< n;i++)
printf("%5d",a[i]);
simplesel(a,b,n);

printf("\nArray After Sorting : ");
for(i=0;i< n;i++)
printf("%5d",b[i]);
getch();
return 0;
}
/* OUTPUT
Enter The number Of Elements : 10

Element 1 : 21

Element 2 : 25

Element 3 : 63

Element 4 : 45

Element 5 : 1

Element 6 : 147

Element 7 : 10

Element 8 : 78

Element 9 : 96

Element 10 : 5
Array Befor Sorting : 21 25 63 45 1 147 10 78 96 5
Array After Sorting : 1 5 10 21 25 45 63 78 96 147
*/

1 comment:

Anonymous said...

Bitch... for c++??? fuck u asshole.. u dickhead...

Your Ad Here