Insertion Sort - Part 2

  • + 0 comments

    There's more than one way to do it,

    def insertionSort2(n, arr):
        if n <= 1:
            return
        for i in range(1, n):
            j = i
            while j > 0 and arr[j-1] > arr[j]:
                arr[j], arr[j-1] = arr[j-1], arr[j]
                j -= 1
            print(" ".join(map(str, arr)))