diff options
author | internetlandlord <f.fredhenry@gmail.com> | 2022-10-20 14:05:49 -0500 |
---|---|---|
committer | internetlandlord <f.fredhenry@gmail.com> | 2022-10-20 14:05:49 -0500 |
commit | 55b8e36aa3ed67aec9f9a69a9631630b842e0cd6 (patch) | |
tree | ffb1ec5dea5e29f564af5ed55079cba3bbe45257 | |
parent | cbb3b74f42824a5e178c556c6b7db6810232e441 (diff) |
Working insertion sort, needs full functionality added.
-rwxr-xr-x | insertion-sort.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/insertion-sort.py b/insertion-sort.py new file mode 100755 index 0000000..350c88b --- /dev/null +++ b/insertion-sort.py @@ -0,0 +1,27 @@ +#!/bin/python3 + +import inputoutput as io +import csv +import sys + + +# insertion sort algorithm, as function +def insertionSort(data): + for i in range(1, len(data)): + key = data[i] + j = i - 1 + + # left comparison + while j >= 0 and key < data[j]: + data[j + 1] = data[j] + j = j - 1 + + # move key after element smaller than it + data[j + 1] = key + +testarr = [99,77,44,22,11,33] +print(testarr) +insertionSort(testarr) +#FIXME: no return argument needed! + +print(testarr) |