最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
go語言單詞首字母排序 go開頭的詞組

golang排序問題求助

如果是只有這幾個的話 我們可以考慮自定義一個排序類型

成都創(chuàng)新互聯(lián)是一家專業(yè)提供克拉瑪依企業(yè)網(wǎng)站建設(shè),專注與成都做網(wǎng)站、成都網(wǎng)站建設(shè)、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為克拉瑪依眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡(luò)公司優(yōu)惠進(jìn)行中。

func TestSort(t *testing.T) {

data := []string{"三級", "一級", "二級"}

rule := map[string]int{

"一級": 1,

"二級": 2,

"三級": 3,

}

self := SelfSort{

Rule: rule,

Data: data,

}

sort.Sort(self)

fmt.Println(self.Data)

}

type SelfSort struct {

Rule map[string]int

Data []string

}

func (p SelfSort) Len() int? ? ? ? ? ?{ return len(p.Data) }

func (p SelfSort) Less(i, j int) bool { return p.Rule[p.Data[i]] p.Rule[p.Data[j]] }

func (p SelfSort) Swap(i, j int)? ? ? { p.Data[i], p.Data[j] = p.Data[j], p.Data[i] }

如過很多 就是真的要比較中文的話, 就用這種

package mainimport ( ? ?"bytes"

"fmt"

"io/ioutil"

"sort"

"golang.org/x/text/encoding/simplifiedchinese"

"golang.org/x/text/transform")//ByPinyin is customized sort interface to sort string by Chinese PinYintype ByPinyin []stringfunc (s ByPinyin) Len() int ? ? ?{ return len(s) }func (s ByPinyin) Swap(i, j int) { s[i], s[j] = s[j], s[i] }func (s ByPinyin) Less(i, j int) bool {

a, _ := UTF82GBK(s[i])

b, _ := UTF82GBK(s[j])

bLen := len(b) ? ?for idx, chr := range a { ? ? ? ?if idx bLen-1 { ? ? ? ? ? ?return false

} ? ? ? ?if chr != b[idx] { ? ? ? ? ? ?return chr b[idx]

}

} ? ?return true}//UTF82GBK : transform UTF8 rune into GBK byte arrayfunc UTF82GBK(src string) ([]byte, error) {

GB18030 := simplifiedchinese.All[0] ? ?return ioutil.ReadAll(transform.NewReader(bytes.NewReader([]byte(src)), GB18030.NewEncoder()))

}//GBK2UTF8 : transform ?GBK byte array into UTF8 stringfunc GBK2UTF8(src []byte) (string, error) {

GB18030 := simplifiedchinese.All[0]

bytes, err := ioutil.ReadAll(transform.NewReader(bytes.NewReader(src), GB18030.NewDecoder())) ? ?return string(bytes), err

}func main() {

b := []string{"哈", "呼", "嚯", "ha", ","}

sort.Strings(b) ? ?//output: [, ha 呼 哈 嚯]

fmt.Println("Default sort: ", b)

sort.Sort(ByPinyin(b)) ? ?//output: [, ha 哈 呼 嚯]

fmt.Println("By Pinyin sort: ", b)

}

copy from?網(wǎng)頁鏈接

Go語言如何給字符串排序

因?yàn)閏har *strings[]不是指針而是指針數(shù)組,那么

temp = strings[top];

strings[top] = strings[seek];

strings[seek] = temp;

這種交換交換的就是主調(diào)函數(shù)中的數(shù)組中的指針,把指向字符串的指針順序改變了,當(dāng)然按次序輸出就達(dá)到排序目的了……

英語單詞順序排列怎么寫?

英語單詞順序排列就是首字母按26英語字母表順序排列,從abcd開始。


名稱欄目:go語言單詞首字母排序 go開頭的詞組
當(dāng)前鏈接:http://fisionsoft.com.cn/article/dodpppe.html