# ---- Here's what we did in class ---- # # TODO : debug this and get it working .... # # original = [10, 20, 50, 13, 7, 8, 12] ## # find smallest : 7 ## # remove it, put it in a new list on the rightmost # sorted = [7] # original = [10, 20, 50, 13, 8, 12] ## # do that again ## sorted = [7, 8] ## original [10, 20, 50, 13, 12] # # Our recipe in pseudo-code is : # # make an empty new list to put the results in # loop until the new list has all the numbers : # find the smallest remaining in the original # move it to the end of the new list # mark it as no longer in the original list def sort1(numbers): newlist = [] # loop until we're done while len(newlist) < len(numbers): # find smallest in numbers smallest = 10000 # something bigger than any in the list i_smallest = None # will be an error if we use this unchanged for i in range(len(numbers)): if numbers[i] != None: if numbers[i] < smallest: i_smallest = i smallest = numbers[i] newlist.append(smallest) numbers[i] = None return newlist