Last active
April 16, 2020 01:42
-
-
Save ShamsAnsari/65bb38b570aa0fd7e329de927264a013 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: []): | |
# Traverse through all array elements | |
for i in range(len(arr)): | |
# Find the minimum element in remaining | |
# unsorted array | |
min_idx = i | |
for j in range(i+1, len(arr)): | |
if arr[min_idx] > arr[j]: | |
min_idx = j | |
# Swap the found minimum element with | |
# the first element | |
arr[i], arr[min_idx] = arr[min_idx], arr[i] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment