//PROGRAM FOR SELECTION SORT
#include"stdio.h"
#include"conio.h"
void ssort(int a[],int n)
{
int i,j,pos,small,temp;
for(i=0;i< n;i++)
{
small=a[i];
for(j=i+1;j< n;j++)
{
if(small>a[j])
{
small=a[j];
pos=j;
}
}
if(small!=a[i])
{
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
}
printf("AFTER ITERATION %d : \n",i+1);
for(j=0;j< n;j++)
{
printf("%d ",a[j]);
}
}
}
void main()
{
int a[20],i,n;
clrscr();
printf("ENTER HOW MANY ELEMENTS YOU WANT TO ENTER");
scanf("%d",&n);
for(i=0;i< n;i++)
scanf("%d",&a[i]);
ssort(a,n);
getch();
}
Monday, September 1, 2008
Selection sort
Posted by Nanya at 8:03 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment