8种排序之间的关系

(2)实例:

(3)用java实现

1. 2. 3. 4. 5.

import java.util.ArrayList; import java.util.List;

public class radixSort { int

a[]={49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,99,98,54,101,56,17,18,23,34,15,35,25,53,51}; 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.

public radixSort(){ sort(a);

for(int i=0;i

public void sort(int[] array){

//首先确定排序的趟数; int max=array[0];

for(int i=1;imax){ max=array[i]; } }

int time=0; //判断位数; while(max>0){ max/=10;

25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60.

time++; }

//建立10个队列;

List queue=new ArrayList(); for(int i=0;i<10;i++){

ArrayList queue1=new ArrayList(); queue.add(queue1); }

//进行time次分配和收集; for(int i=0;i

//分配数组元素;

for(int j=0;j

ArrayList queue2=queue.get(x); queue2.add(array[j]); queue.set(x, queue2); }

int count=0;//元素计数器; //收集队列元素;

for(int k=0;k<10;k++){ while(queue.get(k).size()>0){

ArrayList queue3=queue.get(k); array[count]=queue3.get(0); queue3.remove(0); count++; } } } } }

i+1)/(int)Math.pow(10, i);

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4