Created
February 2, 2017 06:10
-
-
Save czheo/bc0d61fb9efd82effe3163fc8364113f to your computer and use it in GitHub Desktop.
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(lst): | |
i = 0 | |
n = len(lst) | |
while i < n: | |
min_pos = i | |
for j in range(i, n): | |
if lst[j] < lst[min_pos]: | |
min_pos = j | |
target = lst[min_pos] | |
j = min_pos | |
while j > i: | |
lst[j] = lst[j-1] | |
j -= 1 | |
lst[i] = target | |
i += 1 | |
lst = [3,2,2,4,5,6,7,9,9,6,4,2,1] | |
selection_sort(lst) | |
print(lst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment