import java.util.LinkedList; import java.util.Random; class Num{ private int pos1; public int getPos1() { return pos1; } public void setPos1(int pos1) { this.pos1 = pos1; } public int getPos10() { return pos10; } public void setPos10(int pos10) { this.pos10 = pos10; } public int getPos100() { return pos100; } public void setPos100(int pos100) { this.pos100 = pos100; } public int getPos1000() { return pos1000; } public void setPos1000(int pos1000) { this.pos1000 = pos1000; } private int pos10; private int pos100; private int pos1000; public Num(int x) { pos1=x%10; pos10=((x%1000)%100)/10; pos100=(x%1000)/100; pos1000=x/1000; } public String toString() { String str=""; if (pos1000!=0) { str+=pos1000; } if (pos100!=0) { str+=pos100; } if (pos10!=0) { str+=pos10; } str+=pos1; return str; } } public class LSD_No_Position { @SuppressWarnings("unchecked") static void lsdSort(LinkedList<Num> lst) { LinkedList[] digit=new LinkedList[10]; for (int i = 0; i < digit.length; i++)digit[i]=new LinkedList();//不清楚里面有多少个值,用LinkedList装 //分配 while (lst.size()>0) { Num n=lst.remove(); digit[n.getPos1()].add(n); } //收集 for (int i = 0; i < digit.length; i++) lst.addAll(digit[i]); /*更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/*/ digit=new LinkedList[10]; for (int i = 0; i < digit.length; i++)digit[i]=new LinkedList();//不清楚里面有多少个值,用LinkedList装 //分配 while (lst.size()>0) { Num n=lst.remove(); Num n2=n; digit[n.getPos10()].add(n); } //收集 for (int i = 0; i < digit.length; i++)lst.addAll(digit[i]); digit=new LinkedList[10]; for (int i = 0; i < digit.length; i++)digit[i]=new LinkedList();//不清楚里面有多少个值,用LinkedList装 //分配 while (lst.size()>0) { Num n=lst.remove(); int x=n.getPos100(); digit[n.getPos100()].add(n); } //收集 for (int i = 0; i < digit.length; i++)lst.addAll(digit[i]); digit=new LinkedList[10]; for (int i = 0; i < digit.length; i++)digit[i]=new LinkedList();//不清楚里面有多少个值,用LinkedList装 //分配 while (lst.size()>0) { Num n=lst.remove(); int x1=n.getPos1(); int x10=n.getPos10(); int x100=n.getPos100(); int x1000=n.getPos1000(); digit[n.getPos1000()].add(n); } //收集 for (int i = 0; i < digit.length; i++)lst.addAll(digit[i]); } public static void main(String[] args) { // TODO Auto-generated method stub Random r=new Random(); LinkedList<Num> list=new LinkedList<Num>(); /* for (int i = 0; i < 5; i++) { list.add(new Num(r.nextInt(10000))); }*/ list.add(new Num(2740)); list.add(new Num(6263)); list.add(new Num(5156)); list.add(new Num(623)); list.add(new Num(9345)); lsdSort(list); System.out.println(list); } }
以上代码用随机数放进去,结果未排序,但是换成随机生成对应的数放进去,结果就是排序的,求解,若解决的请站内联系
从键盘读入一个由字母构成的串(不大于30个字符)。从该串中取出3个不重复的字符,求所有的取法。取出的字符,要求按字母升序排列成一个串。
不同的取法输出顺序可以不考虑。
例如:
输入:
abc
则输出:
abc
输入:
abcd
则输出:
abc
abd
acd
bcd
输入:
abcaa
则输出:
abc
import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Scanner; import java.util.Set; public class UniqueAlphaSort { /** * @param args */ @SuppressWarnings("unchecked") public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String str=scanner.nextLine(); Set alphaSet=new HashSet(); for (int i = 0; i < str.length(); i++) { alphaSet.add(str.charAt(i)); } List<Character> list=new ArrayList<Character>(); Iterator iterator=alphaSet.iterator(); while (iterator.hasNext()) { list.add((Character)iterator.next()); } //排序 for (int i = list.size()-1; i >0 ; i--) { for (int j = 0; j < i; j++) { if (list.get(j)>list.get(j+1)) { char tmp=list.get(j); list.set(j, list.get(j+1)); list.set(j+1, tmp); } } } for (int i = 0; i < list.size()-2; i++) { for (int j = i+1; j < list.size()-1; j++) { for (int j2 = j+1; j2 < list.size(); j2++) { String x=list.get(i).toString(); String x1=list.get(j).toString(); String x2=list.get(j2).toString(); System.out.println(x+x1+x2); } } } } }
作者:csdn博客 u010026901
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索int
, list
, new
, scanner
, close() scanner java
, linkedlist
, digital
, public
, pos
, lenet iter 10000
, scanner键盘输入stringjava
, LST基数排序
addAll
链式基数排序、链式基数排序算法、链式基数排序代码、链式开沟机、链式法则,以便于您获取更多的相关知识。