-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarytree.go
More file actions
49 lines (43 loc) · 1.33 KB
/
Copy pathbinarytree.go
File metadata and controls
49 lines (43 loc) · 1.33 KB
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 searchalgorithms
// TODO: implement a binary search tree;
// Example:
// 5
// / \
// 9 11
// / \ / \
// 3 5 7 2
// /
// (6)
//
// Methods:
// Add: adds a new node to the tree according to the following rule: new nodes
// SMALLER than the parent go to the left, new nodes LARGER or IDENTICAL to
// the parent go the right; this procedure is done recursively until a parent
// without a child in the particular position is found and the new node will
// be inserted in that position; e.g.: tree.Add(6) --> right --> left --> left
// Tree implements a binary search tree with a certain value at its root and
// right and left children (both stored in the root node)
type Tree struct {
root *Node
depth int
}
// Node is a node in a binary search tree
type Node struct {
leftChild *Node
rightChild *Node
data interface{}
}
// Add adds a new node to a binary search tree
func (t *Tree) Add(data interface{}) {
// TODO: implement
}
// Delete removes the deepest node of a binary search tree that holds a certain data
// value and returns true if a value was removes; a parent node cannot be removes
// with this method
func (t *Tree) Delete(Data interface{}) bool {
// TODO: implement
}
// Depth returns the depth of a binary search tree
func (t *Tree) Depth() int {
return t.depth
}