思路:在一般的排序方法之上,只是在比较的时候采用一点大小写统一比较的方法
/** * @author ZTX * 字符数组排序 * 结果为:一大一小,顺序排列 * 2013年11月18日19:33:13--2013年11月18日19:51:35 * 思路:在一般的排序方法之上,只是在比较的时候采用一点大小写统一比较的方法 */ public class RankChar { public static void main(String args[]){ char chars[]={'a','b','D','c','B','a','b','D','c','B','v','b','b','b','b'}; System.out.println("排序前:"); for(char a:chars){ System.out.print(a); } for(int i=0;i<chars.length-1;i++){ int k=i; for(int j=i+1;j<chars.length;j++){ if(compare(chars[j],chars[k])){ char temp=chars[k]; chars[k]=chars[j]; chars[j]=temp; } } } System.out.println("排序后:"); for(char a:chars){ System.out.print(a); } } private static boolean compare(char c, char d) { // TODO Auto-generated method stub //都是大写,都是小写,一大一小 if(c>='a'&&c<='z'&&d>='a'&&d<='z'){ if(c<d)return true; else return false; } if(c>='A'&&c<='Z'&&d>='A'&&d<='Z'){ if(c<d)return true; else return false; } if(c>='a'&&c<='z'&&d>='A'&&d<='Z'){//c是小写 if(c<=d+32)return true; else return false; } if(c>='A'&&c<='Z'&&d>='a'&&d<='z'){//c是小写 if(c+32<d)return true; else return false; } return false; } }