SELECTION SORT algorithm implementation in C++
|
Download Attachment
|
/***********************************/ /*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(); }
|
|
|
|
|
Share this article
| Print |
Article read by 2534 times
|
|
|