Created
December 15, 2015 12:03
-
-
Save Nata01/a22a2e3d564eb5c76523 to your computer and use it in GitHub Desktop.
Selection sort
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
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