I’m losing faith in my programming skills today, so I’ve decided to re-implement sorting functions. Each day I’ll try to decrease the complexity of the algorithms, but, this day being the first, I’ll give you a quadratic insertion sort. This is an insertion sort, right, or is it shell sort? Heh…
def insertionSort(arr): for i in range(1, len(arr)): t = arr[i] for j in range(0, i): if(t < arr[j]): z = arr[j] arr[j] = t t = z arr[i] = t return arr
What should be next? Bubble sort? Heap sort? Come back tomorrow for a better algorithm. If you find a bug, please report it!
