Skip to content

Instantly share code, notes, and snippets.

@hfadev
Created July 29, 2012 10:55
Show Gist options
  • Select an option

  • Save hfadev/3197561 to your computer and use it in GitHub Desktop.

Select an option

Save hfadev/3197561 to your computer and use it in GitHub Desktop.
C: Selection Sort
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