Created
June 19, 2018 08:30
-
-
Save xuhang57/68c95b9b6f589d7be18e8587f02fb431 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
def selection_sort(arr): | |
for i in range(len(arr)): | |
min_idx = i | |
for j in range(i+1, len(arr)): | |
if arr[min_idx] > arr[j]: | |
min_idx = j | |
arr[i], arr[min_idx] = arr[min_idx], arr[i] | |
return arr | |
selection_sort([12,4,5,6,7,3,1,15]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment