Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Insertion Sort, el más sencillo pero el más ineficiente. O(n^2)
- def insertion_sort(array):
- for i in range(len(array) - 1): #El primer ciclo for va desde el primer elemento hasta el penúltimo.
- for j in range(i + 1, len(array)): #El segundo ciclo for va desde el segundo elemento, hasta el último, iterando siempre por delante del i.
- if array[i] < array[j]: #La condición que necesites.
- array[i], array[j] = array[j], array[i] #Intercambia valores [i] con [j] y viceversa
- return array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement