You are viewing a single comment's thread. Return to all comments →
Python: Modifying j>0 to j>=0 is the only change.
def insertion_sort(l): for i in range(1, len(l)): j = i-1 key = l[i] while (j >= 0) and (l[j] > key): l[j+1] = l[j] j -= 1 l[j+1] = key m = int(input().strip()) ar = [int(i) for i in input().strip().split()] insertion_sort(ar) print(" ".join(map(str,ar)))
Seems like cookies are disabled on this browser, please enable them to open this website
Correctness and the Loop Invariant
You are viewing a single comment's thread. Return to all comments →
Python: Modifying j>0 to j>=0 is the only change.