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
上一篇:如何用Python实现常见机器学习算法-1


下一篇:Python自学笔记-装饰器1(廖雪峰的网站)