Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #make a bubblesort function
- numbers = [1,2,5,8,7,9,12,51,41,87,95,98,992,52,472,21,43]
- def bubblesort(list): #define the bubblesort function
- sorted = list[:] #copy of old list(numbers)
- sort = True
- while sort == True: #while loop start, then sets sort to False, if it has to perform action, sets sort back to True
- sort = False #if it has to perform no action,sort stays False, while loop ends
- for i in range(len(sorted) - 1):
- if sorted[i] > sorted[i+1]:
- sorted[i], sorted[i+1] = sorted[i+1], sorted[i]
- sort = True #turns sort back to True if action performed
- print(sorted)
- bubblesort(numbers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement