• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

包演示;

导入Java。util。数组;

公共类P49 {

//计数排序

//思路为用辅助空间下标对应元素值,下标放的值对应元素出现次数。然后遍历辅助空间,就能有序填回原来数组。

//适用于数据密集并且峰值较小的数组,否则会浪费很多空间

公共静态void main(String[] args) {

int[] arr={10,3,15,7,20 };

计数排序(arr);

系统。出去。println(数组。tostring(arr));

}

静态void countSort(int[] arr) {

int max value=arr[0];

for(int I=1;iarr。长度;i ) {

if(arrmaxValue) {

最大值=arr

}

}

int[]help=new int[最大值1];

for(int I=0;iarr。长度;i ) {//对出现次数进行计数

help[arr];

}

int arrIndex=0;

for(int I=0;ihelp.lengthi ) {

while(help0) {

arr[arrIndex]=I;

help-;

}

}

}

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now