mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-17 06:00:58 +00:00
Add divide and conquer go code (#638)
* feat: Add Go code to binary search recursion under divide and conquer * style: Code comment standardization * style: modify function comment * fix: fixed error when the list is empty * Update print_utils.go * Delete print_utils_test.go * feat: add Go code to divide and conquer * Update build_tree.go * style: modify function name --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// File: hanota_test.go
|
||||
// Created Time: 2023-07-21
|
||||
// Author: hongyun-robot (1836017030@qq.com)
|
||||
|
||||
package chapter_divide_and_conquer
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"fmt"
|
||||
. "github.com/krahets/hello-algo/pkg"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHanota(t *testing.T) {
|
||||
// 列表尾部是柱子顶部
|
||||
A := list.New()
|
||||
for i := 5; i > 0; i-- {
|
||||
A.PushBack(i)
|
||||
}
|
||||
B := list.New()
|
||||
C := list.New()
|
||||
fmt.Println("初始状态下:")
|
||||
fmt.Print("A = ")
|
||||
PrintList(A)
|
||||
fmt.Print("B = ")
|
||||
PrintList(B)
|
||||
fmt.Print("C = ")
|
||||
PrintList(C)
|
||||
|
||||
hanota(A, B, C)
|
||||
|
||||
fmt.Println("圆盘移动完成后:")
|
||||
fmt.Print("A = ")
|
||||
PrintList(A)
|
||||
fmt.Print("B = ")
|
||||
PrintList(B)
|
||||
fmt.Print("C = ")
|
||||
PrintList(C)
|
||||
}
|
||||
Reference in New Issue
Block a user