feat(Go-Tool):修改单测位置,添加lomuto查找第k小元素算法代码及其单测(分治法)

This commit is contained in:
huangzj
2020-08-18 17:29:42 +08:00
parent 3f0e3b27f7
commit fa58e1a97f
27 changed files with 322 additions and 251 deletions
+37
View File
@@ -0,0 +1,37 @@
/*
* @Author : huangzj
* @Time : 2020/8/18 14:54
* @Description
*/
package search
import (
"fmt"
"testing"
)
func TestPartition(t *testing.T) {
list := []int{99, 1, 2, 3, 4, 100, 200, 90, 5}
s := partition(list, 0, 9-1)
fmt.Println(fmt.Sprintf("当前第一个元素应该存在位置为:%d", s))
for _, r := range list {
fmt.Print(r, " ")
}
s = partition(list, 0, 9-1)
fmt.Println(fmt.Sprintf("当前第一个元素应该存在位置为:%d", s))
for _, r := range list {
fmt.Print(r, " ")
}
}
func TestLomutoQuiteSelect(t *testing.T) {
for k := 1; k <= 9; k++ {
s := LomutoQuiteSelect([]int{99, 1, 2, 3, 4, 100, 200, 90, 5}, k)
fmt.Println(fmt.Sprintf("当前第%d个小的元素是:%d", k, s))
fmt.Println()
}
}