title: Implementing Radix sort recursively - how to print the elements at the end?
body: <p><strong>Note:</strong></p>
  
  <p>I already asked a specific question on this programm <a href="https://stackoverflow.com/questions/41322457/i-am-stuck-at-implementing-radix-sort-recursively/41322892?noredirect=1#comment69849442_41322892">before</a>, but now I'm stuck at the very last step and I guess it might be better to open a new thread for it. </p>
  
  <p><strong>Description:</strong></p>
  
  <p>I'm required to implement a programm that sorts numbers ranging from 0 to 99999 recursively (this is basically Radix sort). The process itself is kinda simpel: The user types in an array that contains those numbers in the main method. Then, the main method calls for the sort-method where I create a two-dimensional array named 'space' with 10 rows and 1 column. Then, I divide every number in the array by the digit, which would be 10.000 in the first run. So, for example, 23456 / 10000 = 2,3456 = 2 (in java), hence, the programm puts this number in space[2][0], so in the second row. Then, we take this entire row and extend it, which is done in the putInBucket-method. We do this in order to make sure that we can put another number into the same row. </p>
  
  <p>We do this for every number that is inside the 'numbers'-array. Then, we want to work with these rows and sort them again by the same principle, but now we take a look at the second digit. We want to do this from left to right, not from right to left. So, if our second row would look like this</p>
  
  <p>[23456, 24567],</p>
  
  <p>we'd want to compare the 3 and the 4. In order to do so, we calculate digit / 10 in each recursive call. If the digit is 0, there is nothing to sort anymore. </p>
  
  <p>The recursive call itself works with the rows from 0 to 9 where we put in the different numbers before and now sorts them again by putting them in different rows. </p>
  
  <p><strong>Question:</strong></p>
  
  <p>I think the programm does what it is supposed to do. Unfortunately, I don't know how to print the result properly. For example, in the code below, I tried to print out the bucket in the main method, but it only gives me exactly the array that I just typed in, so that can't be right. </p>
  
  <p>I need to start with all the elements in the row 9, and if this row contains more than one number, I'd have to sort them by the results I got in the recursive call.</p>
  
  <p>Does anyone have an idea how to implement this properly? Thanks in advance!</p>
  
  <pre><code>public static int[] sort(int[] numbers, int digit) {
  
    if (numbers.length &lt;= 1 || digits == 0)
      return numbers;
  
    int[][]space = new int[10][1];
    int i, j = 0;
  
    for (j = 0; j &lt; numbers.length; j++) {
      i = numbers[j] / digit % 10;
      space[i][0] = numbers[j];
      space[i] = putInBucket(space[i], numbers[j]);
    }
  
    digit = digit / 10;
  
    for (i = 0; i &lt; 9; i++) {
      sort(space[i], digit); 
    }
  
    return numbers
  
  }
  
  private static int[] putInBucket(int[] bucket, int number) {
  
    int[] bucket_new = new int[bucket.length+1];
  
    for (int i = 1; i &lt; bucket_new.length; i++) {
      bucket_new[i] = bucket[i-1];
    }
  
    return bucket_new;
  
  }
  
  public static void main (String [] argv) {
  
    int[] numbers = IO.readInts("Numbers: ");
    int digit = 10000;
    int[] bucket = sort(numbers, digit); 
  
    for (int i = 0; i &lt; bucket.length; i++) {
      System.out.println(bucket[i]);
  
  }
  </code></pre>