import java.util.Scanner; /** * 把数组排成最小的数[3 32 321],结果:321323;最小;注意,要考虑大数问题
* 主要是排序问题 * @author dell * */ public class Main15 { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); Main15 main15=new Main15(); int n; String[] numb; System.out.println("开始..... "); while(scanner.hasNext()){ n=scanner.nextInt(); if(n<=0){ System.out.println("输入不合法默认为10"); } numb=new String[n]; System.out.println("输入数组元素值"); for(int i=0;i<n;i++){ numb[i]=scanner.next(); } numb=main15.sortArray(numb,0,n-1); StringBuilder strBuilder=new StringBuilder(numb[0]); for(int i=1;i<n;i++){ strBuilder.append(numb[i]); } System.out.println(strBuilder); } } private String[] sortArray(String[] numb,int p,int q) { // TODO Auto-generated method stub if(p<q){ int mid=partition(numb,p,q); sortArray(numb, p, mid-1); sortArray(numb, mid+1, q); } return numb; } private int partition(String[] numb,int p,int q){ int i=p; int j; String tmp1,tmp2,tmp3; for(j=p;j<q;j++){ tmp1=numb[j]+numb[q]; tmp2=numb[q]+numb[j]; if(tmp1.compareTo(tmp2)<0){ tmp1=numb[i]; numb[i]=numb[j]; numb[j]=tmp1; i++; } } tmp1=numb[i]; numb[i]=numb[j]; numb[j]=tmp1; return i; } }