Advertisement
chrisCNG

bubbleSort

Mar 9th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. # Implementing a Bubble Sort
  2. chrisList = [66,22,33,55,77,88,30,20,50,60,11,13,19]
  3. #sort function
  4. def bub_sort(aList):
  5.     sortList = aList[:]
  6.     changes = True
  7.     while changes:
  8.         changes = False
  9.         for i in range(len(aList)-1):
  10.             if sortList[i] > sortList[i+1]:
  11.                 sortList[i] , sortList[i+1] = sortList[i+1] , sortList[i]
  12.                 changes = True
  13.     print(sortList)
  14. #output result
  15. print(chrisList)
  16. #perform the sort
  17. bub_sort(chrisList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement