import java.util.Scanner;
public class RadixSort
{
public static void main(String[] args)
{
Scanner userinput = new Scanner(System.in);
System.out.print("Please enter the size of the array. ");
//User is prompted to enter the size of the array.
int count = userinput.nextInt();
int[] numbers = new int[count];
QueueLinkedList[] queue = new QueueLinkedList[10];
for(int i=0; i<queue.length; i++)
{
queue[i] = new QueueLinkedList();
}
//Generates random integers.
for(int i=0; i<numbers.length; i++)
{
numbers[i] = (int)(Math.random()*1001);
System.out.print(numbers[i]+", ");
}
System.out.println();
for(int j=1; j<=4; j++)
{
for(int i=0; i<numbers.length; i++)
{
int temp = 0;
queue[getRadix(numbers[i],j)].enqueue(numbers[i]);
}
for(int i=0; i<queue.length; i++)
{
int index=0;
while(!queue[i].isEmpty())
{
numbers[index] = queue[i].dequeueInt();
System.out.print(numbers[index]+", ");
index++;
}
}System.out.println();
}
}
public static int getRadix(int number, int radix)
{
int result = (int)(number / Math.pow(10,radix-1)) % 10;
return result;
}
}