-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.go
49 lines (44 loc) · 1.23 KB
/
example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import "fmt"
/**
* Main function
*/
func main() {
// Create a complete tree
tree := Tree{}
tree.root = newNode(1)
tree.root.left = newNode(2)
tree.root.right = newNode(3)
tree.root.left.left = newNode(4)
tree.root.left.right = newNode(5)
tree.root.right.left = newNode(6)
tree.root.right.right = newNode(7)
tree.root.left.left.left = newNode(8)
tree.root.left.left.right = newNode(9)
tree.root.left.right.left = newNode(10)
tree.root.left.right.right = newNode(11)
tree.root.right.left.left = newNode(12)
tree.root.right.left.right = newNode(13)
tree.root.right.right.left = newNode(14)
tree.root.right.right.right = newNode(15)
if tree.isComplete() {
fmt.Println("The tree is complete")
} else {
fmt.Println("The tree is not complete")
}
// Create a non-complete tree
tree = Tree{}
tree.root = newNode(1)
tree.root.left = newNode(2)
tree.root.right = newNode(3)
tree.root.left.left = newNode(4)
tree.root.left.right = newNode(5)
tree.root.right.left = newNode(6)
tree.root.right.right = newNode(7)
tree.root.left.left.right = newNode(9)
if tree.isComplete() {
fmt.Println("The tree is complete")
} else {
fmt.Println("The tree is not complete")
}
}