代码拉取完成,页面将自动刷新
package wek5;
import java.util.LinkedList;
import java.util.Queue;
public class RadixSort
{
/**
*Performs a radix sort on a set of numeric values.
*/
public static void main(String[] args)
{
int[] list = {7843, 4568, 8765, 6543, 7865, 4532, 9987, 3241,
6589, 6622, 1211};
String temp;
Integer numObj;
int digit, num;
Queue<Integer>[] digitQueues = (LinkedList<Integer>[])(new LinkedList[10]);
for (int digitVal = 0; digitVal <= 9; digitVal++)
digitQueues[digitVal] = (Queue<Integer>)(new LinkedList<Integer>());
// sort the list
for (int position=0; position <= 3; position++)
{
for (int scan=0; scan < list.length; scan++)
{
temp = String.valueOf(list[scan]);
digit = Character.digit(temp.charAt(3-position), 10);
digitQueues[digit].add(list[scan]);
}
// gather numbers back into list
num = 0;
for (int digitVal = 0; digitVal <= 9; digitVal++)
{
while (!(digitQueues[digitVal].isEmpty()))
{
numObj = digitQueues[digitVal].remove();
list[num] = numObj.intValue();
num++;
}
}
}
// output the sorted list
for (int scan=0; scan < list.length; scan++)
System.out.println(list[scan]);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。