How to program for insertion sort in python


How to program for insertion sort in python

      def insertionSort(arr,n):
                   for i in range(1, n):
                        key = arr[i]
                           j = i-1
                  while j >=0 and key < arr[j] :
                       arr[j+1] = arr[j]
                          j -= 1
                          arr[j+1] = key
                          array=[]
                       n=int(input("Enter the size of the array"))
                   print("Enter the array")
               for x in range(n):
            x=int(input())
         array.append(x)
       insertionSort(array,n)
     print ("Sorted array is:")
    for i in range(n):

    print(array[i])
      

Output:-


Post a Comment

0 Comments