标签:
冒泡排序注意三点:
示例代码一:
s = [3, 4, 1, 6, 2, 9, 7, 0, 8, 5] # bubble_sort for i in range(0, len(s) - 1): for j in range(i + 1, 0, -1): if s[j] < s[j - 1]: s[j], s[j - 1] = s[j - 1], s[j] for m in range(0, len(s)): print(s[m])
示例代码二:
1 s = [3, 4, 1, 6, 2, 9, 7, 0, 8, 5] 2 3 4 for i in range(0, len(s)): 5 for j in range(i, 0, -1): 6 if s[j] < s[j - 1]: 7 s[j], s[j - 1] = s[j - 1], s[j] 8 9 for m in range(0, len(s)): 10 print(s[m])
标签:
原文地址:http://www.cnblogs.com/ucos/p/5857020.html