Created
February 17, 2016 13:27
-
-
Save 78526Nasir/bd09e7265cee16bae774 to your computer and use it in GitHub Desktop.
Selection Sort Implementation in C using Array !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Selection Sort /// | |
#include<stdio.h> | |
main() | |
{ | |
int a[100],i,j,minIndex,temp,n; | |
printf("Enter How many elements on your Array :"); | |
scanf("%d",&n); | |
printf("\nEnter %d values :",n); | |
for(i=0;i<n;i++) | |
scanf("%d",&a[i]); | |
printf("\nSelection Sort"); | |
for(i=0;i<n-1;i++) | |
{ | |
minIndex=i; | |
for(j=i+1;j<n;j++) | |
{ | |
if(a[minIndex]>a[j]) | |
{ | |
minIndex=j; | |
} | |
} | |
temp=a[minIndex]; | |
a[minIndex]=a[i]; | |
a[i]=temp; | |
} | |
printf("\n\n"); | |
for(i=0;i<n;i++) | |
printf("%d ",a[i]); | |
printf("\n"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment