Select Git revision
-
Romain Vuillemot authoredRomain Vuillemot authored
selection.py 546 B
def selectionSort(l: list = []) -> list:
"""Tri par selection en ligne"""
for i in range(0, len(l)):
min = i
for j in range(i+1, len(l)):
if(l[j] < l[min]):
min = j
tmp = l[i]
l[i] = l[min]
l[min] = tmp
return l
if __name__=="__main__":
liste = [54,26,93,17,77,31,44,55,20]
assert(sorted(liste) == selectionSort(liste.copy()))
assert([] == selectionSort([]))
assert([1] == selectionSort([1]))
assert([1, 1] == selectionSort([1, 1]))