Skip to content

Commit

Permalink
Added Insertion Sort Code using Python
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurangisinha committed Oct 7, 2020
1 parent 6e827aa commit 255dd75
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 255dd75

Please sign in to comment.