百家姓排序,提供样例, 包括JS思路,Java思路
提供了绝佳的思路!
第一种:js实现
<script>
let gender = ["赵六","钱老","孙子","李叔","周末","吴王","郑公","王梓","慕容","东方"]
let newGender = ["李叔凡","东方红","吴王","东方朔","钱学森","郑公瑾","慕容复","王梓","赵六","孙子","周末"]
// gender.map((item,index)=>console.log(item,item.replace(item,index)))
let array = []
for(var i=0;i<gender.length;i++){
for(var j=0;j<newGender.length;j++){
if(gender[i].charAt(0)==newGender[j].charAt(0)){
array.push(newGender[j])
}
}
}
console.log("array="+array);
</script>
第二种: java实现方式
创建hashMap, 添加姓氏表数据,然后创建hash排序方式