Files
hello-algo/en/codes/go/chapter_tree/binary_search_tree_test.go
Yudong Jin 2778a6f9c7 Translate all code to English (#1836)
* Review the EN heading format.

* Fix pythontutor headings.

* Fix pythontutor headings.

* bug fixes

* Fix headings in **/summary.md

* Revisit the CN-to-EN translation for Python code using Claude-4.5

* Revisit the CN-to-EN translation for Java code using Claude-4.5

* Revisit the CN-to-EN translation for Cpp code using Claude-4.5.

* Fix the dictionary.

* Fix cpp code translation for the multipart strings.

* Translate Go code to English.

* Update workflows to test EN code.

* Add EN translation for C.

* Add EN translation for CSharp.

* Add EN translation for Swift.

* Trigger the CI check.

* Revert.

* Update en/hash_map.md

* Add the EN version of Dart code.

* Add the EN version of Kotlin code.

* Add missing code files.

* Add the EN version of JavaScript code.

* Add the EN version of TypeScript code.

* Fix the workflows.

* Add the EN version of Ruby code.

* Add the EN version of Rust code.

* Update the CI check for the English version  code.

* Update Python CI check.

* Fix cmakelists for en/C code.

* Fix Ruby comments
2025-12-31 07:44:52 +08:00

46 lines
1.1 KiB
Go

// File: binary_search_tree_test.go
// Created Time: 2022-11-26
// Author: Reanon (793584285@qq.com)
package chapter_tree
import (
"fmt"
"testing"
)
func TestBinarySearchTree(t *testing.T) {
bst := newBinarySearchTree()
nums := []int{8, 4, 12, 2, 6, 10, 14, 1, 3, 5, 7, 9, 11, 13, 15}
// Please note that different insertion orders will generate different binary trees, this sequence can generate a perfect binary tree
for _, num := range nums {
bst.insert(num)
}
fmt.Println("\nInitialized binary tree is:")
bst.print()
// Get root node
node := bst.getRoot()
fmt.Println("\nRoot node of binary tree is:", node.Val)
// Search node
node = bst.search(7)
fmt.Println("Found node object is", node, ", node value =", node.Val)
// Insert node
bst.insert(16)
fmt.Println("\nAfter inserting node 16, binary tree is:")
bst.print()
// Remove node
bst.remove(1)
fmt.Println("\nAfter removing node 1, binary tree is:")
bst.print()
bst.remove(2)
fmt.Println("\nAfter removing node 2, binary tree is:")
bst.print()
bst.remove(4)
fmt.Println("\nAfter removing node 4, binary tree is:")
bst.print()
}