Created
July 29, 2012 10:55
-
-
Save hfadev/3197561 to your computer and use it in GitHub Desktop.
C: Selection Sort
This file contains hidden or 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
| void swap(int *a,int*b){ | |
| int t = *a; | |
| *a = *b; | |
| *b = t; | |
| } | |
| void selectionSort(int* a,int n){ | |
| int min; | |
| int i,k; | |
| for (i = 0; i < n-1; ++i) | |
| { | |
| min = i; | |
| for(k = i+1; k < n; k++){ | |
| if( a[k] < a[min]){ | |
| min = k; | |
| } | |
| } | |
| if( min != i ){ | |
| swap(&a[i],&a[min]); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment