Advertisement
jhoward48

Untitled

Jan 27th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. def bubbleSort(unsorted):
  2.    
  3.      print (" your unsorted list is ", unsorted,)
  4.      swaps=True
  5.      while swaps:
  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.                    swaps=True
  12.                    return unsorted
  13.                    
  14.      else:
  15.           swaps=False
  16.           while swaps:
  17.                for i in range (len(unsorted)-1):
  18.                     if unsorted[i]<unsorted[i+1]:
  19.                          temp=unsorted[i+1]
  20.                          unsorted[i]=unsorted[i]
  21.                          swaps=False
  22.                          return unsorted
  23.      
  24.  
  25. unsorted = [5,9,5,8,1,3]
  26. bubbleSort(unsorted)
  27. bubbleSort(unsorted)
  28. bubbleSort(unsorted)
  29. bubbleSort(unsorted)
  30. bubbleSort(unsorted)
  31. bubbleSort(unsorted)
  32. bubbleSort(unsorted)
  33. bubbleSort(unsorted)
  34. bubbleSort(unsorted)
  35. bubbleSort(unsorted)
  36. bubbleSort(unsorted)
  37. print(unsorted)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement