- public class SortTest{
- public static void main(String[] args) {
- int[] array = new int[] {5,21,2,2,12};
- int [] temp = new int[100];
- for(int i = 0;i<temp.length;i++){
- temp[i] = 0;
- }
- for(int i = 0;i<array.length;i++){
- int t = array[i];
- temp[t] ++;
- }
- for(int i = 0;i<temp.length;i++){
- if (temp[i]>0){
- for (int j = 1;j<=temp[i];j++){
- System.out.println(i);
- }
- }
- }
- }
- }
桶排序 时间复杂度:O(n)
缺点:不能排负数小数,空间复杂度也不确定
优点:快,很可能比快速还要快,但快速用的太多