代码:

#coding:utf-8
#author:徐卜灵
import math
#print math.ceil(3.2) 向上取整4.0
#print math.floor(3.2) 向下取整3.0
#print math.log(100,10) base 为10 结果为2.0
def Radiz_sort(L):
k = int(math.ceil(math.log(max(L),10))) #最大为几位数 max(L)
bucket = [[] for i in range(10)] #建立10个空列表
print bucket
for i in range(1,k+1):
for j in L:
bucket[j/(10**(i-1))%(10 ** i)].append(j)
del L[:]
for z in bucket:
L += z
del z[:]
print L
# bucket = [[] for i in range(10)]
# print bucket
L = [1, 3, 2, 32, 5, 4]
Radiz_sort(L)

怎么少了一种?先写这些,以后再修改一下。

05-11 20:06