冒泡,选择,插入

def bublle_sort(lists):
    
    n = len(lists)
    for i in range(n-1):
        for j in range(n-1-i):
            if lists[j] > lists[j+1]:
                lists[j],lists[j+1] = lists[j+1],lists[j]
    print(lists)



def selecet_sort(lists):
     n = len(lists)
     for i in range(n-1):
         min_index = i
         for j in range(i+1,n):
             if lists[j] < lists[min_index]:
                 min_index = j
         if min_index != i:
            lists[i],lists[min_index] = lists[min_index],lists[i]
     print(lists)



def insert_sort(lists):
    n = len(lists)  
    for i in range(1,n):
        value = lists[i]
        index = i
        while index > 0 and value < lists[index-1]:
            lists[index] = lists[index-1]
            index -= 1
        lists[index] = value      
    print(lists)


posted @ 2020-04-01 15:01  ColaIce  阅读(97)  评论(0)    收藏  举报