Insertion Sort - Part 2

  • + 0 comments

    Solution from my side (Python)

    def insertionSort1(n, arr):
        for i in range(len(arr)-1):
            if(arr[i]>arr[i+1]):
                temp = arr[i+1]
                arr[i+1]=arr[i]
                arr[i]=temp
                for j in range(i+1):
                    for k in range(j,i+1):
                        if(arr[j]>arr[k]):
                            temp = arr[k]
                            arr[k] = arr[j]
                            arr[j] = temp
                for num in arr:    
                    print(num,end=' ')
                print()
            else:
                for num in arr:    
                    print(num,end=' ')
                print()