一、数据结构基础

    a、什么是数据结构

        Python之数据结构基础

      b、数据结构的分类

       Python之数据结构基础

       c、列表 

        Python之数据结构基础

import random
from timewrap import *

def list_to_buckets(li, iteration):
    """
    :param li: 列表
    :param iteration: 装桶是第几次迭代
    :return:
    """
    buckets = [[] for _ in range(10)]
    for num in li:
        digit = (num // (10 ** iteration)) % 10
        buckets[digit].append(num)
    return buckets

def buckets_to_list(buckets):
    return [num for bucket in buckets for num in bucket]
    # li = []
    # for bucket in buckets:
    #     for num in bucket:
    #         li.append(num)

@cal_time
def radix_sort(li):
    maxval = max(li) # 10000
    it = 0
    while 10 ** it <= maxval:
        li = buckets_to_list(list_to_buckets(li, it))
        it += 1
    return li

li = [random.randint(0,1000) for _ in range(100000)]
radix_sort(li)
列表

相关文章:

  • 2021-07-26
  • 2021-06-17
  • 2021-07-09
  • 2021-12-11
  • 2022-02-09
  • 2021-10-03
  • 2021-10-12
猜你喜欢
  • 2021-09-06
  • 2022-02-08
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2021-11-18
相关资源
相似解决方案