#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/11/17 14:42 # @Author : gylhaut # @Site : "http://www.cnblogs.com/gylhaut/" # @File : main.py # @Software: PyCharm # 冒泡排序方法 def DubSort(data): for j in range(1,len(data)): for i in range(len(data)-j): if(data[i]>data[i+1]): # temp = data[i+1] # data[i+1] = data[i] # data[i] =temp data[i+1],data[i]= data[i],data[i+1] return data if __name__ == '__main__': data = [4,10,1,23,5,45,7,21,89,3,9,32,11,34,8,6,28] print(data) print("-----------------------------------") data = DubSort(data) print(data)
冒泡排序时间复杂度:O(n^2)