Advertisement
dmesticg

Comp Sci

Mar 5th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. data = [20,40,90,50,60,70,80,110,100,30]
  2.  
  3. def bubbleSort(what):
  4. isSorted = False
  5. while not(isSorted):
  6. for i in range(len(what) - 1):
  7. for j in range(len(what) - 1 - i):
  8. if what[j] > what[j+1]:
  9. what[j], what[j+1] = what[j+1],what[j]
  10. else:
  11. isSorted = True
  12. return what
  13.  
  14. def selectionSort(what):
  15. for i in range(len(what)):
  16. minpos = 0
  17. for j in range(i,len(what)):
  18. if what[j] < what[minpos]:
  19. minpos = j
  20. temp = what[i]
  21. what[i],what[minpos] = what[minpos],temp
  22. what.append(what[0])
  23. what.pop(0)
  24. return(what)
  25.  
  26. print(selectionSort(data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement