Skip to content

Commit

Permalink
Update insert_sort.py
Browse files Browse the repository at this point in the history
  • Loading branch information
aentisom committed Oct 19, 2018
1 parent c401bfb commit bcf7451
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions insert_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def myInsertSort(theList):

newList = []
newList.append(theList[0])

for i in theList[1:]:

if i <= newList[0]:
newList.insert(0,i)
elif i >= newList[-1]:
newList.append(i)
else:
l = len(newList)

for j in range(l):

if newList[j] <= i and i <= newList[j + 1]:
newList.insert(j + 1,i)
break


return newList

print(myInsertSort([5,4,3,2,1]))

0 comments on commit bcf7451

Please sign in to comment.