Skip to content

Instantly share code, notes, and snippets.

@effective-light
Last active June 19, 2017 21:05
Show Gist options
  • Save effective-light/b5c5fa25be47741e6b5189c6b6488019 to your computer and use it in GitHub Desktop.
Save effective-light/b5c5fa25be47741e6b5189c6b6488019 to your computer and use it in GitHub Desktop.
Sorting Algorithms
def selection_sort(lst):
for i in range(len(lst) - 1):
min_index = i
for j in range(i + 1, len(lst)):
if lst[j] < lst[min_index]:
min_index = j
lst[i], lst[min_index] = lst[min_index], lst[i]
def insertion_sort(lst):
for i in range(1, len(lst)):
current = lst[i]
j = i
while j > 0 and lst[j - 1] > current:
lst[j] = lst[j - 1]
j -= 1
lst[j] = current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment