Ticker

6/recent/ticker-posts

Write a program to implement insertion sort


                          In This post we have write a c program to implement  insertion sort.  for subject of Analysis of Algorithms | Computer Engineering | Mumbai University (MU) | (Semester 4) 

Write a program to implement insertion sort.


Program:

def insertion_sort(alist):

for i in range(1, len(alist)):

temp = alist[i]

j = i - 1

while (j >= 0 and temp < alist[j]):

alist[j + 1] = alist[j]

j = j - 1

alist[j + 1] = temp

alist = input('Enter the list of numbers: ').split()

alist = [int(x) for x in alist]

insertion_sort(alist)

print('Sorted list: ', end='')

print(alist)

Output:



Conclusion:

Thus we perform the program to implement insertion sort.

Post a Comment

0 Comments