Computer Science, asked by yukesh70, 8 months ago

write a program to sort a sequence using insertion sort​

Answers

Answered by Anonymous
1

\huge\mathcal{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)

Answered by Anonymous
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