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

python 冒泡排序

#!/usr/bin/python # -*- coding: utf-8 -*-

array=[15,1,20,13,8] def bubble_sort(array):

    for i in range(len(array),0,-1):

      for j in range(len(array)-1):

         if array[j] > array[j+1]:

             tmp = array[j]

             array[j] = array[j+1]

             array[j+1] = tmp

    print("result: " + str(array))

bubble_sort(array)

print("bubble_sort success!!!")

python 冒泡排序