Advertisement
jhoward48

Untitled

Jan 25th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def bubbleSort(unsorted):
  2.      print (" your unsorted list is ", unsorted)
  3.      swaps=True
  4.      while swaps:
  5.           swaps=False
  6.           for i in range(len(unsorted)-1):
  7.                if unsorted[i]>unsorted[i+1]:
  8.                    temp = unsorted[i]
  9.                    unsorted[i] = unsorted[i+1]
  10.                    unsorted[i+1] = temp
  11.                    swapped =True
  12.                    return unsorted
  13.           else:
  14.                swaps=False
  15.                return unsorted
  16.  
  17.  
  18. unsorted = [5,9,5,8,1,3]
  19. bubbleSort(unsorted)
  20. print(unsorted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement