• Python与Go插入排序


    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # 插入排序
    # 时间复杂度 O(n^2)
    import time
    
    
    def logger(func):
        start_time = time.time()
    
        def inner(*args, **kwargs):  # 1
            return func(*args, **kwargs)  # 2
    
        print(time.time() - start_time)
        return inner
    
    
    @logger
    def insertion_sort(array):
        length = len(array)
        for i in range(1, length):
            for m in range(i):
                if array[i] < array[m]:
                    array[i], array[m] = array[m], array[i]
    
    
    if __name__ == '__main__':
        aa = [1, 4, 3, 5, 6, 2, 6, 0, 0]
        insertion_sort(aa)
        print(aa)
    package main
    // 插入排序
    // 时间复杂度 O(n^2)
    import "fmt"
    
    func insertionSort(array []int)  {
        length := len(array)
        for i := 1; i < length; i ++ {
            for m := 0; m < i; m ++ {
                if array[i] > array[m] {
                    array[i], array[m] = array[m], array[i]
                }
            }
        }
    }
    
    func main()  {
        aa := []int{1, 4, 3, 5, 6, 2, 6, 0, 0}
        insertionSort(aa)
        fmt.Println(aa)
    }
  • 相关阅读:
    CCPC-Wannafly Winter Camp Day4 Div1
    CCPC-Wannafly Winter Camp Day4 Div1
    CCPC-Wannafly Winter Camp Day4 Div1
    CCPC-Wannafly Winter Camp Day5 Div1
    Luogu 1603
    洛谷试炼场
    Codeforces 1100
    Codeforces 1099E
    Codeforces 1099
    Luogu 1093
  • 原文地址:https://www.cnblogs.com/shiluoliming/p/9835225.html
Copyright © 2020-2023  润新知