def insertion_sort(unsorted_arr):
         for i in range(1, len(unsorted_arr)):
            j = i-1
            nxt_element = unsorted_arr[i]
      # Compare the current element with next one
         while (unsorted_arr[j] > nxt_element) and (j >= 0):
            unsorted_arr[j+1] = unsorted_arr[j]
            j=j-1
         unsorted_arr[j+1] = nxt_element
      arr= [45,89,56,78,90,12,10,2,34,1]
      insertion_sort(arr)
      print(arr)
      

      Python language logoInsertion Sort

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.