按字母排序

对字符串进行排序,用任意一种编程语言来实现,不能使用现有的类,在排序中,字符串“Bc”,“Ad”,“aC”,“Hello”,“Xman”,“little”,“During”,“day”能够排序成“Ad”,"aC",“Bc”,“During”,“day”,“Hello”,“little”,“Hello”,也就是说,在排序的过程并不是传统的按照字符串排序,在排序中还需要将小写字母一并排序,也就是说a字符串要在B或b之前。

 

import java.util.Arrays;
import java.util.Comparator;

public class Test {
public static void main(String[] args) {

	String[] strs={"Bc","Ad","aC","Hello","Xman","little","During","day"};
	Arrays.sort(strs, new Comparator(){
		int cha='a'-'A';
		public int compare(String o1, String o2) {
			char[] so1=o1.toCharArray();
			char[] so2=o2.toCharArray();
			int min=so1.length
 

你可能感兴趣的:(面试相关,编程)