Files
goNum/MaxMinSort.go
Black Ghost 96fccdb6ef update comments
update comments in all of files in convenient to generate package information using `godoc` command or give tips in LiteIDE editor when the cursor keeps resting on a function or method.
2019-03-01 10:10:32 +08:00

52 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// MaxMinSort
/*
------------------------------------------------------
作者 : Black Ghost
日期 : 2018-11-19
版本 : 0.0.0
------------------------------------------------------
向量从大到小的排序
------------------------------------------------------
输入 :
a a 被排序向量
输出 :
sol 解值
err 解出标志false-未解出或达到步数上限;
true-全部解出
------------------------------------------------------
*/
package goNum
// MaxMinSort 向量从大到小的排序
func MaxMinSort(a []float64) ([]float64, bool) {
/*
向量从大到小的排序
输入 :
a a 被排序向量
输出 :
sol 解值
err 解出标志false-未解出或达到步数上限;
true-全部解出
*/
var err bool = false
var temp float64
var n int = len(a)
sol := make([]float64, n)
for i := 0; i < n; i++ {
sol[i] = a[i]
}
for i := 0; i < n; i++ {
for j := i + 1; j < n; j++ {
if sol[i] < sol[j] {
temp = sol[j]
sol[j] = sol[i]
sol[i] = temp
}
}
}
err = true
return sol, err
}