0

如何将每个元素添加到数组队列中?基本上,如果我有一个队列数组,其中每个索引都是一个数组队列,其中包含 1、10、100 等,将相应的 6 位数字放在数组 a 的另一个索引中。例如,如果 a[1] 是 123456,那么我怎样才能使下面的代码保持 arr[1] 654321?我之前发布过一个与此类似的问题,但我只是想解决这个问题。

public static void radixSort(int[] a) {
  //Create an array of 10 empty array queues
  Queue[] arr =  new Queue[a.length];

  for (int i = 0; i < arr.length; i++)
      arr[i] = new ArrayQueue();

  for (int place = 1; place <= 100000; place *= 10) {
      for (int i = 0; i < a.length; i++) {
          arr[i].add(selectDigit(a[i],place));
         // System.out.println("i: " + i + " a[i]: " + a[i] + " place: " + place + " digit: "  + selectDigit(a[i],place));
      }
  }

 // for (int i = 0; i < arr.length; i++)
    //  System.out.print(arr[i].remove()+ " ");
          //for (int j = 0; j < arr.length; j++)
            //  a[j] = (Integer) arr[j].remove();   
  } 
4

1 回答 1

2

本教程可能会有所帮助: http: //www.sourcecodesworld.com/articles/java/java-data-structures/Radix_sort.asp

这似乎是一个很好的步行。

于 2012-11-19T04:58:12.787 回答