首页 > 代码库 > python冒泡排序

python冒泡排序

def bubble_sort(list):
	for i in range(len(list)):
		for j in (range(i,len(list))):
			if list[j] < list[i]:
				temp = list[j]
				list[j] = list[i]
				list[i] = temp

list = [2,3,4,1,7,4,3,0,9]

bubble_sort(list)

list

[0, 1, 2, 3, 3, 4, 4, 7, 9]