1. |
function RadixSort(A,d){ |
2. |
tableProcess
= new Array(); |
3. |
for(var i
= d; i >=
0; i--){ |
4. |
b
= new Array(A.length); |
5. |
b
= insertRadix(A,i); |
6. |
temp
= new Array(A.length); |
7. |
temp
= CountingSort(b,temp,b.length); |
8. |
A
= Sort(A,temp,i); |
9. |
} |
10. |
return A; |
11. |
} |
12. |
|
13. |
function insertRadix(A,i){ |
14. |
var temp; |
15. |
for(var j
= 0; j
< A.length; j++){ |
16. |
temp
= A[j] + ''; |
17. |
b[j]
= temp.charAt(i); |
18. |
} |
19. |
return b; |
20. |
} |
21. |
|
22. |
function Sort(A,B,d){ |
23. |
var temp, j
= 0; |
24. |
var arr
= new Array(B.length); |
25. |
for(;;){ |
26. |
if(j
>= B.length) break; |
27. |
else{ |
28. |
for(var i
= 0; i
< A.length; i++){ |
29. |
temp
= A[i] + ''; |
30. |
if(temp.charAt(d)
== B[j] && A[i] !=
null){ |
31. |
arr[j++]
= parseInt(temp); |
32. |
A[i]
= null; |
33. |
break; |
34. |
} |
35. |
} |
36. |
} |
37. |
} |
38. |
return arr; |
39. |
} |