Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #bubble sort
- def bubble_sort(my_list):
- list_copy=my_list
- swapped=True
- while swapped==True:
- i=0
- swapped=False #reset flag
- while i<(len(list_copy)-1): #first to penultimate value
- if list_copy[i]>list_copy[i+1]:
- swapped=True
- temp=list_copy[i] #switch values
- list_copy[i]=list_copy[i+1]
- list_copy[i+1]=temp
- i+=1
- return list_copy
- #test
- orig_list=[3,5,7,2,9,4,5,2,7,0]
- print(bubble_sort(orig_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement