Tweet
/* Selection sort using minimum */
#include<stdio.h>
int swap(int *a,int x,int y)
{
int temp=*(a+x);
*(a+x)=*(a+y);
*(a+y)=temp;
}
void selsort(int a[],int n)
{
int i,j,min,pos;
for(i=0;i<n;i++)
{
min=a[i];
for(j=i+1;j<n;j++)
{
if(a[j]<min)
{
min=a[j];
pos=j;
}
}
swap(a,i,pos);
}
printf("SORTED ARRAY : ");
for(i=0;i<n;i++)
printf("%4d",a[i]);
printf("\n");
}
main()
{
int i,n;
printf("Enter array capacity : \n");
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
*(a+i)=rand()%100;
printf("INITIAL ARRAY : ");
for(i=0;i<n;i++)
printf("%4d",a[i]);
printf("\n");
selsort(a,n);
}
Selection Sort using minimum number in C
Posted by
LAHAUL SETH
~
Selection Sort using minimum number in C
2011-11-29T10:59:00+05:30
LAHAUL SETH
Programming in C
|
Sorting
|
Comments
Selection Sort using minimum number in C
2011-11-29T10:59:00+05:30
LAHAUL SETH
Programming in C
|
Sorting
|