write a program to sort a sequence using insertion sort
Answers
Answered by
1
a = [16, 19, 11, 15, 10, 12, 14]
#iterating over a
for i in a:
j = a.index(i)
#i is not the first element
while j>0:
#not in order
if a[j-1] > a[j]:
#swap
a[j-1],a[j] = a[j],a[j-1]
else:
#in order
break
j = j-1
print (a)
Answered by
1
Answer:
a = [16, 19, 11, 15, 10, 12, 14]
#iterating over a
for i in a:
j = a.index(i)
#i is not the first element
while j>0:
#not in order
if a[j-1] > a[j]:
#swap
a[j-1],a[j] = a[j],a[j-1]
else:
#in order
break
j = j-1
print (a
Similar questions