Java program to print the radix sort using while loop

Java program to print the radix sort using while loop. In java programming, this is used to sort the data in a specific order. Java is a programming language that allows you to perform radix type. In java programming, this is used to sort the data in a specific order. To sort the elements in java programs, a variety of important methods were used in the industry.

import java.util.ArrayList;
import java.util.List;
public class Main
{
public static void main(String[] args)
{
int[] num = {5,565,64,4343,778,6656,567,456,7,8,8889,6678,9000};
radixsort(num);
for (int h : num)
System.out.print(h + " ");
}
public static void radixsort(int[] input)
{
List<Integer>[] buckets = new ArrayList[10];
for (int i = 0; i < buckets.length; i++) {
buckets[i] = new ArrayList<Integer>();
}
boolean flag = false;
int tmp = -1, divisor = 1;
while (!flag) {
flag = true;
for (Integer i : input) {
tmp = i / divisor;
buckets[tmp % 10].add(i);
if (flag && tmp > 0) {
flag = false;
}
}
int a = 0;
for (int b = 0; b < 10; b++) {
for (Integer i : buckets[b]) {
input[a++] = i;
}
buckets[b].clear();
}
divisor *= 10;
}
}
}

 

Output: 5 7 8 64 456 565 567 778 4343 6656 6678 8889 9000