Skip to content

Instantly share code, notes, and snippets.

@akiltipu
Last active July 13, 2020 22:56
Show Gist options
  • Save akiltipu/40431149a686ef11f8c432af66def166 to your computer and use it in GitHub Desktop.
Save akiltipu/40431149a686ef11f8c432af66def166 to your computer and use it in GitHub Desktop.
Implementation of selection sort algorithm with python 3
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