1. 程式人生 > >排序演算法之-基數排序

排序演算法之-基數排序

 

public static void radixSort(int[] arr, int d)
   {
      int i;
      // current digit found by dividing by 10^power
      int power = 1;
      // allocate 10 null references to a LinkedQueue
      LinkedQueue[] digitQueue = new LinkedQueue[10];

      // initialize each element of digitQueue to be
      // an empty queue
      for (i=0;i < digitQueue.length;i++)
         digitQueue[i] = new LinkedQueue();

      for (i=0;i < d;i++)
      {
         distribute(arr, digitQueue, power);
         collect(digitQueue, arr);
         power *= 10;
      }
   }