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
27 changes: 27 additions & 0 deletions selectionSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def findLowest(list_: list):
"""
Finds the lowest number from the list and returns it
"""
lowest = list_[0]
for item in list_:
if item < lowest:
lowest = item

return lowest


def selectionSort(list_: list):
"""
Sorts a list using selection sort algorithm
"""
array = list_
result = []

while not len(array) == 0:
lowest = findLowest(array)
lowestIndex = array.index(lowest)

result.append(lowest)
array.pop(lowestIndex)

return result