python插入排序和sort时间比较
来源:互联网 发布:网络博客被骗怎么追 编辑:程序博客网 时间:2024/04/30 01:03
# 插入排序函数def insertSort(a): for i in range(len(a)-1): for j in range(i+1,len(a)): if a[i]>a[j]: temp = a[i] a[i] = a[j] a[j] = temp return a
下面是自己写的插入排序和自带的sort比较
tb = {} for i in range(0,1000): tb[i] = {} tb[i][1] = random.randint(1, 100) tb[i][2] = random.randint(1, 100) tb[i][3] = random.randint(1, 100) tb[i][4] = random.randint(1, 100) tb[i][5] = random.randint(1, 100)import datetimeprint datetime.datetime.now()cloth = []cloth2 = []def getmax(attr): for c in tb: val = tb[c][attr[0]] + tb[c][attr[1]] + tb[c][attr[2]] + tb[c][attr[3]] lenth = len(cloth) if not lenth: cloth.append(val) else: for i in range(0, lenth): if val >= cloth[i]: cloth.insert(i,val) break if i == lenth-1: cloth.append(val)getmax([1,2,3,4]) #print clothprint datetime.datetime.now() def getmax2(attr): for c in tb: val = tb[c][attr[0]] + tb[c][attr[1]] + tb[c][attr[2]] + tb[c][attr[3]] cloth2.append(val)getmax2([1,2,3,4])cloth2.sort()#print clothprint datetime.datetime.now()
下面是结果,python自带的sort函数效率很高
# 000 2015-05-14 17:20:40.328000# 111 2015-05-14 17:20:40.351000# 222 2015-05-14 17:20:40.352000
0 0
- python插入排序和sort时间比较
- Arrays.sort与冒泡排序时间比较
- 插入排序(INSERTION-SORT) PYTHON实现
- Insert Sort & Shell Sort(插入排序和希尔排序)
- 比较排序之插入和归并排序
- 插入排序和希尔排序的比较
- Python提取TOP排名,用插入排序法和二分法排序比较
- 【学习笔记】python版选择排序和插入排序及时间复杂度分析
- 插入排序(insertion sort)
- insertion sort 插入排序
- 插入排序(Insertion Sort)
- 插入排序 Insertion Sort
- 插入排序Insertion sort
- 插入排序 (Insertion Sort)
- Inserting Sort (插入排序)
- sort-插入排序法、
- 插入排序Insertion sort
- 插入排序 Insertion Sort
- Android照片墙的实现
- ffmpeg实现视频合并
- android listview adapter中设置点击直接position被重用问题解决
- 学习Redis就是如此简单
- 课件工具
- python插入排序和sort时间比较
- ArrayAdapter
- 基于局部感受野的极速学习机
- android 四大组件之一Activity
- java 判断字符串是否为空,是否为数字
- 用Flash制作Scorm标准课件
- java——反射
- ftp 21端口被占用解决办法
- 第20题:把只含数字的字符串转换为整数