SELECTION SORT algorithm implementation in C++
/***********************************/ /*PROGRAM TO PREFORM SELECTION SORT*/ /***********************************/
#include < stdio.h> #include < conio.h>
void main() { int a[10],n,i,j,temp,min,loc;
clrscr();
printf("Enter the size of array: "); scanf("%d",&n); printf("\nEnter the elements of array:\n"); for(i=0;i { scanf("%d",&a[i]); } for(i=0;i { min=a[i]; loc=i; for(j=i+1;j { if(min>a[j]) { min=a[j]; loc=j; } } temp=a[i]; a[i]=a[loc]; a[loc]=temp; }
printf("\nAfter sorting the elements of array are:\n"); for(i=0;i { printf("%d ",a[i]); } getch(); }
http://
http://
Contributed by:
Rohit kakria
I am software developer
Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=338
Click here to go on website
|