From d7535395392ed9eb7ed779d9cd7fe84b3e2ce2be Mon Sep 17 00:00:00 2001 From: Jerry Haaser Date: Tue, 14 Apr 2020 09:50:27 -0500 Subject: [PATCH] attempted sorting --- src/iterative_sorting/iterative_sorting.py | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/iterative_sorting/iterative_sorting.py b/src/iterative_sorting/iterative_sorting.py index e27496b3..52e39e7a 100644 --- a/src/iterative_sorting/iterative_sorting.py +++ b/src/iterative_sorting/iterative_sorting.py @@ -1,12 +1,26 @@ # TO-DO: Complete the selection_sort() function below + +thing = [7, 15, 2, 58, 9] + + def selection_sort( arr ): # loop through n-1 elements for i in range(0, len(arr) - 1): cur_index = i smallest_index = cur_index # TO-DO: find next smallest element - # (hint, can do in 3 loc) - + # (hint, can do in 3 loc) + print("cur_index- ", cur_index) + print("smallest_index-", smallest_index) + if smallest_index <= cur_index: + print("made it") + cur_index += 1 + + elif smallest_index > cur_index: + smallest_index = cur_index + cur_index += 1 + + # @@ -17,9 +31,21 @@ def selection_sort( arr ): return arr +print(selection_sort(thing)) + # TO-DO: implement the Bubble Sort function below def bubble_sort( arr ): + #Get first two elements 0, 1 + slot1 = 0 + slot2 = 1 + + + + #compare 0 <= 1 + #swap if false + #move to elements 1,2 + #repeat until there are zero swaps return arr