Skip to content

Instantly share code, notes, and snippets.

@xuhang57
Created June 19, 2018 08:30
Show Gist options
  • Save xuhang57/68c95b9b6f589d7be18e8587f02fb431 to your computer and use it in GitHub Desktop.
Save xuhang57/68c95b9b6f589d7be18e8587f02fb431 to your computer and use it in GitHub Desktop.
Selection Sort
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