File tree 1 file changed +23
-3
lines changed
1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -51,12 +51,32 @@ func (tree *BinaryTree) SearchItem(i int) (*Node, bool) {
51
51
return nil , false
52
52
}
53
53
54
- func (tree * BinaryTree ) GetItems (subtree * Node , callback func (int )) {
54
+ func (tree * BinaryTree ) InorderTraversal (subtree * Node , callback func (int )) {
55
55
if subtree .left != nil {
56
- tree .GetItems (subtree .left , callback )
56
+ tree .InorderTraversal (subtree .left , callback )
57
57
}
58
58
callback (subtree .data )
59
59
if subtree .right != nil {
60
- tree .GetItems (subtree .right , callback )
60
+ tree .InorderTraversal (subtree .right , callback )
61
61
}
62
62
}
63
+
64
+ func (tree * BinaryTree ) PreorderTraversal (subtree * Node , callback func (int )) {
65
+ callback (subtree .data )
66
+ if subtree .left != nil {
67
+ tree .PreorderTraversal (subtree .left , callback )
68
+ }
69
+ if subtree .right != nil {
70
+ tree .PreorderTraversal (subtree .right , callback )
71
+ }
72
+ }
73
+
74
+ func (tree * BinaryTree ) PostorderTraversal (subtree * Node , callback func (int )) {
75
+ if subtree .left != nil {
76
+ tree .PostorderTraversal (subtree .left , callback )
77
+ }
78
+ if subtree .right != nil {
79
+ tree .PostorderTraversal (subtree .right , callback )
80
+ }
81
+ callback (subtree .data )
82
+ }
You can’t perform that action at this time.
0 commit comments