Esempio n. 1
0
func main() {

	inArr := []int{4, 5, 7, 8, 9}
	t1 := getMinimalBST(inArr, 0, len(inArr)-1)
	binarytree.InOrderTraverse(t1)
	fmt.Println("")
}
Esempio n. 2
0
func main() {

	inArr := []int{4, 5, 7, 8, 9}
	t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1)
	binarytree.InOrderTraverse(t1)
	ancestor := findCommonAncestor(t1, t1.Right)
	fmt.Println("Common Ancestor : ", ancestor)
}
Esempio n. 3
0
func main() {

	inArr := []int{4, 5, 7, 8, 9}
	t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1)
	binarytree.InOrderTraverse(t1)
	fmt.Println("Left", t1.Left.Value)
	//Parent is not set in the tree construction for testing
	//in_order_successor := getInOrderSuccessor(t1.Left)
	//fmt.Println("In Order succesor? ", in_order_successor.Value)
}
Esempio n. 4
0
func main() {

	inArr := []int{4, 5, 7, 8, 9}
	t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1)
	binarytree.InOrderTraverse(t1)
	height := getHeight(t1)
	fmt.Println(height)

	fmt.Println("Tree Balanced is ", isBalanced(t1))
}
Esempio n. 5
0
func main() {
	inArr := []int{4, 5, 7, 8, 9}
	t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1)
	binarytree.InOrderTraverse(t1)

	//t1 := binarytree.New(100, 1)
	isBalanced(t1)

	t2 := binarytree.New(100, 1)
	isBalanced(t2)
}
Esempio n. 6
0
func main() {
	inArr := []int{4, 5, 7, 8, 9}
	t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1)
	binarytree.InOrderTraverse(t1)
	var nodeList []*list.List
	getLevelbasedList(&nodeList, t1, 0)
	fmt.Println()
	for _, value := range nodeList {
		fmt.Print("[ ")
		for x := value.Front(); x != nil; x = x.Next() {
			fmt.Print(x.Value.(int), " ")
		}
		fmt.Println("]")
	}
}