计数排序
来源:互联网 发布:ubuntu google输入法 编辑:程序博客网 时间:2024/06/05 16:50
上下界明确时,效率最高的排序方法
package sort;public class CountSort {public static final int SIZE = 100;public static final int MAX = 10000000;public static int[] arr = new int[MAX];static {for (int i = 0; i < MAX; i++) {arr[i] = (int) (SIZE * Math.random());}}public static void sort() {int[] temp = new int[SIZE]; //SIZE是数组元素的上界,下界为0int[] result = new int[arr.length];for (int i = 0; i < arr.length; i++)temp[arr[i]]++;for (int i = 1; i < temp.length; i++) {temp[i] += temp[i - 1];}for (int i = arr.length - 1; i > -1; i--) {result[temp[arr[i]] - 1] = arr[i];temp[arr[i]]--;}for (int i = 0; i < result.length - 1; i++) {if (result[i] > result[i + 1]) {System.err.println("错误");break;}}System.out.println("OK");}public static void main(String[] args) {sort();}}
0 0
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- Javascript的Date类型总结
- Spark--用Java开发微服务
- 51 nod 数组的最大代价
- MapReduce计数器
- Shell Script函数
- 计数排序
- linux 监控线程命令
- 基于KNN算法的约会网站配对效果 python3.2
- HDU 1035 模拟
- post 提交 和 get 提交的区别 文件上传
- Light OJ 1008 Fibsieve`s Fantabulous Birthday(找出数字位置)
- java实现递归快排和非递归快排
- SpringMVC中的java.lang.ClassNotFoundException: org.aspectj.weaver.BCException 调试过程记录
- 数组函数整理