Skip to content

Commit

Permalink
Merge pull request #170 from gaurangisinha/gaurangisinha
Browse files Browse the repository at this point in the history
Added Insertion Sort Code using Python
  • Loading branch information
sanskarseth authored Oct 7, 2020
2 parents 6e827aa + 255dd75 commit cbf1b2e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Insertion_Sort/Insertion_Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Python program for implementation of Insertion Sort

def insertionSort(arr):

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

key = arr[i] # Move elements of arr that are greater than key, to one position ahead of their current position
j = i-1
while j >= 0 and key < arr[j] :
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key

print("Enter the array elements : ")
arr = list(map(int,input().split()))
insertionSort(arr)
print ("\nSorted array is ",str(arr))


0 comments on commit cbf1b2e

Please sign in to comment.