Last active
July 13, 2020 22:56
-
-
Save akiltipu/40431149a686ef11f8c432af66def166 to your computer and use it in GitHub Desktop.
Implementation of selection sort algorithm with python 3
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): | |
n = len(L) | |
for i in range(0, n-1): | |
index_min = i | |
for j in range(i+1, n): | |
if L[j] < L[index_min]: | |
index_min = j | |
if index_min != i: | |
L[i], L[index_min] = L[index_min], L[i] | |
if __name__ == "__main__": | |
L = [10, 5, 2, 8, 7] | |
print("Before sort:", L) | |
selection_sort(L) | |
print("After sort:", L) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment