Last active
June 19, 2017 21:05
-
-
Save effective-light/b5c5fa25be47741e6b5189c6b6488019 to your computer and use it in GitHub Desktop.
Sorting Algorithms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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