Skip to content

Instantly share code, notes, and snippets.

@Nata01
Created December 15, 2015 12:03
Show Gist options
  • Save Nata01/a22a2e3d564eb5c76523 to your computer and use it in GitHub Desktop.
Save Nata01/a22a2e3d564eb5c76523 to your computer and use it in GitHub Desktop.
Selection sort
void selectionSort(int *arr, int length){
for(int i = 0; i < length; i++){
int minIndex = i;
for(int j = i + 1; j < length; j++){
if(arr[minIndex] > arr[j]){
minIndex = j;
}
}
if(minIndex != i){
int temp = arr[minIndex];
arr[minIndex] = arr[i];
arr[i] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment