Python实现常见算法[1]——冒泡排序
#!/usr/bin/python def BUBBLE_SORT(L, x, y): j = y while j>x: i = x while i<j: if L[i] > L[i+1]: temp = L[i] L[i] = L[i+1] L[i+1] = temp i = i+1 j = j-1
算法验证代码
#!/usr/bin/python import random import quik_sort import bubble_sort L = range(100) random.shuffle(L) bubble_sort.BUBBLE_SORT(L, 0, len(L)-1) print L