3. What will be the in-order traversal output of this BST after inserting values in order: 10, 5, 15, 3, 7?
package main
import "fmt"
type Node struct {
value int
left, right *Node
}
func inOrder(root *Node) {
if root == nil {
return
}
inOrder(root.left)
fmt.Print(root.value, " ")
inOrder(root.right)
}
func insert(root *Node, val int) *Node {
if root == nil {
return &Node{value: val}
}
if val < root.value {
root.left = insert(root.left, val)
} else {
root.right = insert(root.right, val)
}
return root
}
func main() {
var root *Node
vals := []int{10, 5, 15, 3, 7}
for _, v := range vals {
root = insert(root, v)
}
inOrder(root)
}