简单桶排序算法-python实现
2015-09-23 11:19
543 查看
#-*- coding: UTF-8 -*- import numpy as np def BucketSort(a, n): barrel = np.zeros((1, n), dtype = 'int32') for i in xrange(0,a.size): barrel[0][a[i]] += 1 k = 0 for i in xrange(0,n): if barrel[0][i] != 0: for j in xrange(0,barrel[0][i]): a[k] = i k += 1 if __name__ == '__main__': a = np.random.randint(0, 100, size = 10) print "Before sorting..." print "---------------------------------------------------------------" print a print "---------------------------------------------------------------" BucketSort(a, 100) print "After sorting..." print "---------------------------------------------------------------" print a print "---------------------------------------------------------------"
相关文章推荐
- 希尔排序算法-python实现
- 用python写MapReduce函数——以WordCount为例
- 基数排序算法-python实现
- 归并排序算法-python实现
- 堆排序算法-python实现
- 插入排序算法-python实现
- 冒泡排序算法-Python实现
- 选择排序算法-python实现
- 快速排序算法-python实现
- python字典按照值排序
- python 时间模块小结
- Python科学计算发行版—Anaconda
- Python json.dumps
- 解决 python用 xlsxwrite 向excel 中写入中文字符串变量 报错
- Python环境及robotframework安装
- python中str函数isdigit、isdecimal、isnumeric的区别
- Python 爬虫进阶必须的几步
- Python特殊语法:filter、map、reduce、lambda
- Python yield 使用浅析
- 【Python之旅】第三篇(二):Pickle序列化