Question

How do I add each element into an arrayqueue? Basically, if I have an array of queues where each index is an arrayqueue that holds the 1s, 10s, 100s, etc. place of a corresponding 6 digit number in another index of array a. For example, if a[1] is 123456 then how can I make the code below hold arr[1] 654321? I've posted a question similar to this before but I'm just trying to get this right.

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();   
  } 
Was it helpful?

Solution

This tutorial might help: http://www.sourcecodesworld.com/articles/java/java-data-structures/Radix_sort.asp

It seems a good walk through.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top