(alist)
| 11 | |
| 12 | # 改进的冒泡排序, 加入一个校验, 如果某次循环发现没有发生数值交换, 直接跳出循环 |
| 13 | def modiBubbleSort(alist): |
| 14 | exchange = True |
| 15 | passnum = len(alist) - 1 |
| 16 | while passnum >= 1 and exchange: |
| 17 | exchange = False |
| 18 | for i in range(passnum): |
| 19 | if alist[i] > alist[i+1]: |
| 20 | alist[i], alist[i+1] = alist[i+1], alist[i] |
| 21 | exchange = True |
| 22 | passnum -= 1 |
| 23 | return alist |
| 24 | |
| 25 | print(bubbleSort(alist)) |
nothing calls this directly
no outgoing calls
no test coverage detected