insertion sort implementation in python

I am working on my Python coding skills and this time reviewing various algorithms with which I have not been in touch for many days. So I start with sorting, here is my code for insertion sort:

def insertion_sort(ara):
for j in range(1, len(ara)):
key = ara[j]
i = j - 1
while i >= 0 and key < ara[i]:
ara[i+1] = ara[i]
i -= 1
ara[i+1] = key

return ara

if __name__ == "__main__":
ara = [10, 5, 2, 9, 4, 8, 9, 2, 1]

Read the entire article at the source link… Tamim Shahriar

#codango #developer #development #coder #coding

We're happy to share this resource that we found. The content displayed on this page is property of it's original author and/or their organization.


Leave a Reply

Your email address will not be published. Required fields are marked *