NewMinimalHeightBST gives the minimal height tree from the given sorted array
(arr []int, low int, high int)
| 89 | |
| 90 | //NewMinimalHeightBST gives the minimal height tree from the given sorted array |
| 91 | func NewMinimalHeightBST(arr []int, low int, high int) *Tree { |
| 92 | if high < low { |
| 93 | return nil |
| 94 | } |
| 95 | mid := (low + high) / 2 |
| 96 | t1 := NewTree() |
| 97 | t1.Value = arr[mid] |
| 98 | t1.Left = NewMinimalHeightBST(arr, low, mid-1) |
| 99 | t1.Right = NewMinimalHeightBST(arr, mid+1, high) |
| 100 | return t1 |
| 101 | } |
| 102 | |
| 103 | //Traverse the tree using in-order traversal |
| 104 | func InOrderTraverse(t *Tree) { |