Skip to content

Commit

Permalink
#258 insertion sort in python
Browse files Browse the repository at this point in the history
  • Loading branch information
realhunter7869 committed Oct 1, 2021
1 parent 224ed7d commit 4ca23c0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ALGORITHMS/Sorting/Insertion Sort/insertionSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def insertionSort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while j >= 0 and key < arr[j] :
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key


lst = [1, 2, 3, 5, 4]
insertionSort(lst)
# since lists are mutable
# the main list itself changes
print(lst)

0 comments on commit 4ca23c0

Please sign in to comment.