Advertisement
joespi

Untitled

Oct 4th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. #Insertion Sort, el más sencillo pero el más ineficiente. O(n^2)
  2. def insertion_sort(array):
  3.     for i in range(len(array) - 1): #El primer ciclo for va desde el primer elemento hasta el penúltimo.
  4.         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.
  5.             if array[i] < array[j]: #La condición que necesites.
  6.                 array[i], array[j] = array[j], array[i] #Intercambia valores [i] con [j] y viceversa
  7.     return array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement