Repository where I mostly put random python scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
480 B

  1. # coding: utf-8
  2. # In[45]:
  3. alist = [54,26,93,17,77,31,44,55,20]
  4. def shortBubbleSort(alist):
  5. exchanges = True
  6. passnum = len(alist)-1
  7. while passnum > 0 and exchanges:
  8. exchanges = False
  9. for i in range(passnum):
  10. if alist[i]>alist[i+1]:
  11. exchanges = True
  12. temp = alist[i]
  13. alist[i] = alist[i+1]
  14. alist[i+1] = temp
  15. passnum = passnum-1
  16. return alist
  17. print(shortBubbleSort(alist))