码迷,mamicode.com
首页 > 编程语言 > 详细

八大排序python实现

时间:2017-07-09 19:39:20      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:color   依次   code   turn   部分   需要   ret   直接插入   insert   

1.直接插入排序:将需要排序的列表分为已排序和未排序部分,依次将未排序部分的数字与已排序部分进行比较,找到比自己小的数字时停止,并插入到该数字后一位

def insertSort(L):
        lenth = len(L)
        for i in range(1, lenth):
                if L[i] < L[i-1]:
                        j = i-1
                        tmp = L[i]
                        while tmp < L[j]:
                                L[j+1] = L[j]
                                j = j-1
                        L[j+1] = tmp
        return L

 

八大排序python实现

标签:color   依次   code   turn   部分   需要   ret   直接插入   insert   

原文地址:http://www.cnblogs.com/lrheisoo/p/7142184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!