Created
December 8, 2017 15:17
-
-
Save srakrn/82fba61c7538b019b0d125e9e700f9a0 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(l): | |
for i in range(len(l)-1): | |
minimum = l[i] | |
minimum_pos = i | |
for j in range(i+1, len(l)): | |
if l[j] < minimum: | |
minimum = l[j] | |
minimum_pos = j | |
l[i], l[minimum_pos] = l[minimum_pos], l[i] | |
return l | |
import random | |
l = [random.randint(1, 20) for _ in range(20)] | |
print(selection_sort(l)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment