Hey If you are beginner and want to learn a python then you are on right path. Learn basic as well as advanced programming in Python.

Search

Python program for Insertion Sort.

PYTHON PROGRAM




n=int(input("Enter array size:"))

print ("Enter",n,"elements in Array:")

a=[]

for i in range(n):

s=int(input())

a.append(s)

for i in range (1,n):

temp=a[i]

j=i-1

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

a[j+1]=a[j]

j -=1

a[j+1]=temp

print ("Element of Array after Insertion Sort are:")

for i in range(n):

print (a[i])






*** Input && Output ***






No comments:

Post a Comment

let me know which type examples you want to comment me.