mirror of
https://gitee.com/chfenger/goNum.git
synced 2025-12-06 16:49:24 +08:00
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.
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// 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
|
||
}
|