#Jonathan Hudson #Student Number 12347890 #Date: 2020-08-26 #Lecture Practice # Sort a list of values using bubble sort def swap(values, i, j): temp = values[i] values[i] = values[j] values[j] = temp def swap2(values, i, j): values[i], values[j] = values[j], values[i] # Perform bubble sort on list of numerical values (smallest to largest) # Parameters # values: a list of numerical values to bubble sort # Returns # nothing is returned # values contains same items but is ordered in increasing numerical def bubbleSort(values): # Sort the values using bubble sort changed = True # Keep looping until we get through the loop without doing any swaps while changed == True: changed = False # For each pair of adjacent elements i = 0 while i < len(values)-1: # If the elements are out of order if values[i] > values[i+1]: swap(values, i, i+1) # Mark that something was changed changed = True i += 1 # List of values values = [1, 3, 7, 5, 9, 2, 6, 8, 4, 0] print(values) bubbleSort(values) print(values)