這篇文章算是做個紀錄
把工作上遇到的問題,想到其他的解法記錄下來
package main
type Sample struct {
	Name    string
	OrderID int
}
var sample [100]Sample
func OrderValue() {
	for i := 0; i < len(sample); i++ {
		for j := i + 1; j < len(sample); j++ {
			if sample[i].OrderID > sample[j].OrderID {
				temp := sample[i]
				sample[i] = sample[j]
				sample[j] = temp
			}
		}
	}
}
package main
type Sample struct {
	Name    string
	OrderID int
}
var sample [100]Sample
func OrderValue() {
	outputSample := make([]Sample, len(sample))
	for index := range sample {
		outputIndex := sample[index].OrderID
		outputSample[outputIndex] = sample[index]
	}
}
用空間換時間是洗澡的時候突然想到的XD
原理就是利用OrderID做為新陣列的index
最後再將該資料插入新陣列