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
24 changes: 16 additions & 8 deletions src/iterative_sorting/iterative_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@ def selection_sort( arr ):
smallest_index = cur_index
# TO-DO: find next smallest element
# (hint, can do in 3 loc)




for j in range (cur_index+1,len(arr)):
#compare all values to value of curr index
# find the smallest
if arr[j]<arr[smallest_index]:
smallest_index=j
# TO-DO: swap




arr[cur_index],arr[smallest_index]=arr[smallest_index],arr[cur_index]
return arr


# TO-DO: implement the Bubble Sort function below
def bubble_sort( arr ):
made_a_swap= True
while made_a_swap:
made_a_swap = False

for i in range(0,len(arr)-1):
j = i+1

if arr[i]>arr[j]:
arr[i],arr[j]=arr[j],arr[i]
made_a_swap=True

return arr


Expand Down