selectionSort([7, 4, 5, 9, 8, 2, 1]) # [1, 2, 4, 5, 7, 8, 9]
selectionSort(['e', 'l', 'a', 'r', 'b', 'o', 'l']) # ['a', 'b', 'e', 'l', 'l', 'o', 'r']
def selectionSort(unsortedData):
for i in range(len(unsortedData)-1, 0, -1):
maxPosition=0
# Buscamos la posicion donde mover el elemento
for j in range(1,i+1):
if unsortedData[j]>unsortedData[maxPosition]:
maxPosition = j
# Intercambiamos los elementos
unsortedData[i], unsortedData[maxPosition] = unsortedData[maxPosition], unsortedData[i]
return unsortedData
Comentarios sobre la versión: 1 (0)
No hay comentarios