mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-23 03:46:05 +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,24 @@
|
||||
// File: build_tree_test.go
|
||||
// Created Time: 2023-07-20
|
||||
// Author: hongyun-robot (1836017030@qq.com)
|
||||
|
||||
package chapter_divide_and_conquer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
. "github.com/krahets/hello-algo/pkg"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildTree(t *testing.T) {
|
||||
preorder := []int{3, 9, 2, 1, 7}
|
||||
inorder := []int{9, 3, 1, 2, 7}
|
||||
fmt.Print("前序遍历 = ")
|
||||
PrintSlice(preorder)
|
||||
fmt.Print("中序遍历 = ")
|
||||
PrintSlice(inorder)
|
||||
|
||||
root := buildTree(preorder, inorder)
|
||||
fmt.Println("构建的二叉树为:")
|
||||
PrintTree(root)
|
||||
}
|
||||
Reference in New Issue
Block a user