计数排序

适用于数据量大,但取值范围小的情况。

package com.example.demo.test;

public class CountSort {

	public static void main(String[] args) {
		int[] array = {4,2,9,8,4,7,6,2,7,9,2,0,8,3,0,6,0,9,1,6,2,8,4,9,0,2,7,4,5,8,9};
		int[] result = sort(array);
		for (int i : result) {
			System.out.print(i);
		}
	}

	private static int[] sort(int[] array) {
		int[] result = new int[array.length];
		int[] count = new int[10];
		for (int i =0;i 0) result[j++] = i;
		}
		return result;
	}
}

 

你可能感兴趣的:(算法,算法)