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

 

posted @ 2016-08-18 14:08  木椅的博客  阅读(177)  评论(0编辑  收藏  举报