Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bubbleSort(unsorted):
- print (" your unsorted list is ", unsorted,)
- swaps=True
- while swaps:
- for i in range(len(unsorted)-1):
- if unsorted[i]>unsorted[i+1]:
- temp = unsorted[i]
- unsorted[i] = unsorted[i+1]
- unsorted[i+1] = temp
- swaps=True
- return unsorted
- else:
- swaps=False
- while swaps:
- for i in range (len(unsorted)-1):
- if unsorted[i]<unsorted[i+1]:
- temp=unsorted[i+1]
- unsorted[i]=unsorted[i]
- swaps=False
- return unsorted
- unsorted = [5,9,5,8,1,3]
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- bubbleSort(unsorted)
- print(unsorted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement