Topic Source Cattle Net: http://www.nowcoder.com/questionTerminal/3c334863c02443cdb61b2d73c1edf071?orderByHotValue=0&query= A set of randomly arranged alphabetic arrays &done=0&pos=9
A set of randomly arranged alphabetic arrays. Write an algorithm with a time complexity of O (n) so that the letters are sorted from small to large in alphabetical order.
Description: Letters are case-sensitive, with the same letters, and lowercase are sorted before uppercase.
Example: R,b,b,b,w,w,b,r,b,w
Sorted by: B,b,b,b,b,r,r,w,w,w
1) Description Ideas (2 points)
2) Please use your familiar programming language code implementation (8 points)
Java Solution version:
import java.util.arraylist;import java.util.collection;import java.util.collections;import java.util.Vector; Public classMydemo { Public Static voidMain (string[] args) {//TODO auto-generated Method StubSystem. out. println (Function ("ABBBDSXAINIKNKDKKKKJJCCDDDCC")); } Public Staticstring function (String inputstring) {ArrayList<Character> arraylist=NewArraylist<> ();//Save uppercase lettersArraylist<character> arraylist2=NewArraylist<> ();//Save lowercase lettersStringBuffer result=NewStringBuffer (); for(intI=0; I<inputstring.length (); i++){ if(Inputstring.charat (i) <'a'){//Uppercase LettersArraylist.add (Inputstring.charat (i)); }Else{arraylist2.add (Inputstring.charat (i)); }} collections.sort (ArrayList); Collections.sort (ARRAYLIST2); for(intI=0; I<arraylist2.size (); i++) {result.append (arrayList2.Get(i)); } for(intI=0; I<arraylist.size (); i++) {result.append (arrayList.Get(i)); } returnresult.tostring (); }}
My Android learning experience: http://jingyan.baidu.com/season/48891
American Regiment 2015 School Recruit Research and development pen question--alphabetical sort