本节课老师留下的思考问题可以这样写吗?
var strArr = ["d", "cd", "bcd","abcd", "abcde","edf", "abb", "a"] ;
func compareTwoString(s1:String,s2:String)->Bool{
if(countElements(s1) < countElements(s2)){
return true ; //长度优先
}
else{
if countElements(s1) > countElements(s2){
return false ; //长度优先
}
var str1 = Array(s1) ;
var str2 = Array(s2) ;
for var i=0, j=0 ; i<str1.count && j<str2.count;(i++,j++){
if str1[i] <= str2[j]{
return true
}
else{
return false ;
}
}
}
return false ;
}
sorted(strArr, compareTwoString )