Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Sorting Algorithms/Python/insertion_sorting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Insertion sorting Algorithm
# @python

def insertion_sort(list_):

for x in range(1, len(list_)):
cursor = list_[x]
pos = x

while pos > 0 and list_[pos - 1] > cursor:
list_[pos] = list_[pos - 1]
pos = pos - 1
list_[pos] = cursor
return list_

array = [15, 2, 4, 50, 30, 2, 0, 1, 4]
sorted = insertion_sort(array)
print(sorted)