1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | /* A C program to perform insertion sort */ #include<stdio.h> #include<stdlib.h> main() { int a[50] , i , j , n ,temp , min; printf("enter the number of elements in array\n"); scanf("%d",&n); // accepts the number of elements. printf("enter all the elements \n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); // accepts all the elements of the array. } for(i=0;i<n-1;i++) { min=i; for(j=i+1;j<n;j++) { if(a[j]<a[min]) min=j; } temp = a[i]; // swapping. a[i] = a[min]; a[min] = temp; } printf("sorted array in Ascending Order is \n"); for(i=0;i<n;i++) { printf("%d\t",a[i]); } } |
New Android apps UniqueKey
Thursday, 28 August 2014
SELECTION SORT
Labels:
C language,
Sorting
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment