## 基数排序 和桶排序 原

pczhangtl

``````import java.util.ArrayList;
import java.util.Queue;

public static void radixSort(int arr[], int maxDigits){
int exp = 1;//10^0;
for(int i =0; i < maxDigits; i++){
ArrayList bucketList[] = new ArrayList[10];
for(int k=0; k < 10; k++){
bucketList[k] = new ArrayList();
}
for(int j =0; j < arr.length; j++){
int number = (arr[j]/exp)%10;
}
exp *= 10;
int index =0;
for(int k=0; k < 10; k++){
for(int num: (ArrayList<Integer>)bucketList[k]){
arr[index] = num;
index++;
}
}
}

System.out.println("Sorted numbers");
for(int i =0; i < arr.length; i++){
System.out.print(arr[i] +", ");
}
}

public static void radixSort1( int[] a)
{
int i, m = a[0], exp = 1, n = a.length;
int[] b = new int[10];
for (i = 1; i < n; i++)
if (a[i] > m)
m = a[i];
while (m / exp > 0)
{
int[] bucket = new int[10];

for (i = 0; i < n; i++)
bucket[(a[i] / exp) % 10]++;
for (i = 1; i < 10; i++)
bucket[i] += bucket[i - 1];
for (i = n - 1; i >= 0; i--)
b[--bucket[(a[i] / exp) % 10]] = a[i];
for (i = 0; i < n; i++)
a[i] = b[i];
exp *= 10;
}
}

if(arr.length == 0)
return;
int[][] np = new int[arr.length][2];
int[] q = new int[0x100];
int i,j,k,l,f = 0;
for(k=0;k<4;k++){
for(i=0;i<(np.length-1);i++)
np[i][1] = i+1;
np[i][1] = -1;
for(i=0;i<q.length;i++)
q[i] = -1;
for(f=i=0;i<arr.length;i++){
j = ((0xFF<<(k<<3))&arr[i])>>(k<<3);
if(q[j] == -1)
l = q[j] = f;
else{
l = q[j];
while(np[l][1] != -1)
l = np[l][1];
np[l][1] = f;
l = np[l][1];
}
f = np[f][1];
np[l][0] = arr[i];
np[l][1] = -1;
}
for(l=q[i=j=0];i<0x100;i++)
for(l=q[i];l!=-1;l=np[l][1])
arr[j++] = np[l][0];
}
}

public static void radixSort4(int A[], int B[], int n, int b, int r, int C[]){
int j ;
int m = b/r;
for(int i = 0; i <r; i++){
}
for(int i = 0, t = 1; i < m; i++, t*=radix2){
for(j = 0; j < radix2; j++){
C[j] = 0;
}

for(j = 0; j < n; j++){
}

for(j = 1; j < radix2; j++){
C[j] = C[j - 1] + C[j];
}

for(j = n -1 ; j >= 0; j--){
}

for(j = 0; j < n; j++){
A[j] = B[j];
}
}
}
/**
* place elements in data into order
*
* @param data array of positive integer values
*/
public static void radixSort2(int [ ] data) {
boolean flag = true;
int divisor = 1;
Queue [ ] buckets = new Queue[10];
for (int i = 0; i < 10; i++)

while (flag) {
flag = false;
// first copy the values into buckets
for (int i = 0; i < data.length; i++) {
int hashIndex = (data[i] / divisor) % 10;
if (hashIndex > 0) flag = true;
}
// then copy the values back into vector
divisor *= 10;
int i = 0;
for (int j = 0; j < 10; j++) {
while (! buckets[j].isEmpty()) {
data[i++] = ival.intValue();
}
}
}
}

// Sort the numbers beginning with least-significant digit

// Largest place for a 32-bit int is the 1 billion's place
for(int place=1; place <= 1000000000; place *= 10){
// Use counting sort at each digit's place
input = countingSort(input, place);
}

return input;
}

private static int[] countingSort(int[] input, int place){
int[] out = new int[input.length];

int[] count = new int[10];

for(int i=0; i < input.length; i++){
int digit = getDigit(input[i], place);
count[digit] += 1;
}

for(int i=1; i < count.length; i++){
count[i] += count[i-1];
}

for(int i = input.length-1; i >= 0; i--){
int digit = getDigit(input[i], place);

out[count[digit]-1] = input[i];
count[digit]--;
}

return out;

}

private static int getDigit(int value, int digitPlace){
return ((value/digitPlace ) % 10);
}

public static void main(String[] args){
int i;
int[] arr = new int[10];
int[] arr1 = new int[10];
int[] arr2 = new int[256];
System.out.print("original: ");
for(i=0;i<arr.length;i++){
arr[i] = (int)(Math.random() * 1024);
System.out.print(arr[i] + " ");
}
radixSort4(arr, arr1, 10, 32, 8, arr2);
System.out.print("\nsorted: ");
for(i=0;i<arr.length;i++)
System.out.print(arr[i] + " ");
System.out.println("\nDone ;-)");
}
}``````

### pczhangtl

02/18
0
0

2017/01/22
0
0

dby_freedom
02/24
0
0

sssssuuuuu666
2017/12/15
0
0

2015/01/11
0
0

sharelocked
56分钟前
2
0
burpsuite无法抓取https数据包

1.将浏览器和burpsuite的代理都设置好 2.在浏览器地址栏输入： http://burp 3.下载下面的证书，并将证书导入浏览器 cacert.der

Frost729

2
0
JeeSite4.x 消息管理、消息推送、消息提醒

ThinkGem

7
0
OpenML

https://www.openml.org/search?type=data

shengjuntu

2
0
java强引用,软引用，弱引用和虚引用

woshixin

1
0