Files

- main.py

main.py

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

```
#http://interactivepython.org/runestone/static/pythonds/SortSearch/TheInsertionSort.html
def insertionSort(items):
for i in range(1,len(items)):
currentvalue = items[i]
print("inserting " + str(items[i]))
position = i
while position>0 and items[position-1]>currentvalue:
items[position]=items[position-1]
position = position-1
items[position]=currentvalue
print(items)
#initialize a list of something, sort it, and print it
numbers = [54,26,93,17,77,31,44,55,20]
print(numbers)
insertionSort(numbers)
print(numbers)
"""
PSEUDOCODE
insertion sort works by maintaining a sorted subset inside the set of items to be sorted
the subset starts with the first item of the total set of items (which is "sorted")
then, one by one, it takes the next item in the set and compares it one by one through the sorted subset, starting with the highest
once the new item is compared to an item is it greater than, it stops and grabs the next unsorted item
repeat these steps as many times as there are items in the set
"""
```