feat(Go-Tool):新增二分法查找算法及其单测、插入查询及其单测、lomuto划分查询第k小元素及其单测、归并排序及其单测、快速排序及其单测.

This commit is contained in:
huangzj
2020-08-20 09:28:35 +08:00
parent fa58e1a97f
commit c2aca17567
12 changed files with 385 additions and 8 deletions
+4 -4
View File
@@ -11,7 +11,7 @@ package search
//start : 开始比较的数字下标
//end :结束比较的数字下标
//作用说明:
func partition(list []int, start int, end int) int {
func LomutoPartition(list []int, start int, end int) int {
moveSubscript := start
compareValue := list[start]
for i := start + 1; i <= end; i++ {
@@ -27,13 +27,13 @@ func partition(list []int, start int, end int) int {
func LomutoQuiteSelect(list []int, pointPosition int) int {
positionCheck(pointPosition, len(list)) //下标校验
nowPosition := partition(list, 0, len(list)-1)
nowPosition := LomutoPartition(list, 0, len(list)-1)
//循环进行lomuto划分处理,知道找到我们需要的那个位置的元素
for nowPosition != pointPosition-1 {
if nowPosition > pointPosition-1 {
nowPosition = partition(list, 0, nowPosition)
nowPosition = LomutoPartition(list, 0, nowPosition)
} else {
nowPosition = partition(list, nowPosition+1, len(list)-1)
nowPosition = LomutoPartition(list, nowPosition+1, len(list)-1)
}
}