冒泡排序
一、代码实现
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 10 09:27:02 2021
@author: lenovo
冒泡排序
"""
def bubble_sort(array):
if(len(array) == 0 or len(array) ==1):
return -1
for i in range(len(array)):
for j in range(len(array)-1):
if array[i] > array[j]:
temp = array[j]
array[j] = array[i]
array[i] = temp
array_sort = [2,4,1,5,6,0,7,3,6]
print(array_sort)
bubble_sort(array_sort)
print(array_sort)
二、打印结果
下一篇
蛮力法之直接选择排序