# Triple order traversal of a binary tree in golang

Go program for Triple order traversal of a binary tree. Here more solutions.

``````package main
import "fmt"
/*
Go program for
Triple order traversal of a binary tree
*/
// Binary Tree node
type TreeNode struct {
data int
left * TreeNode
right * TreeNode
}
func getTreeNode(data int) * TreeNode {
// return new TreeNode
return &TreeNode {
data,
nil,
nil,
}
}
type BinaryTree struct {
root * TreeNode
}
func getBinaryTree() * BinaryTree {
// return new BinaryTree
return &BinaryTree {
nil,
}
}
func(this BinaryTree) tripleOrder(node * TreeNode) {
if node != nil {
// Print preorder node
fmt.Print(" ", node.data)
// Visit left subtree
this.tripleOrder(node.left)
// Print inorder node
fmt.Print(" ", node.data)
// Visit right subtree
this.tripleOrder(node.right)
// Print postorder node
fmt.Print(" ", node.data)
}
}
func main() {
// Create new binary trees
var tree * BinaryTree = getBinaryTree()
/*
4
/ \
/   \
-4     7
/ \     \
2   3     1
/ \   /
6   8 5
/
9
----------------------
Constructing binary tree

*/
tree.root = getTreeNode(4)
tree.root.left = getTreeNode(-4)
tree.root.left.right = getTreeNode(3)
tree.root.left.right.left = getTreeNode(6)
tree.root.left.right.left.left = getTreeNode(9)
tree.root.left.right.right = getTreeNode(8)
tree.root.left.left = getTreeNode(2)
tree.root.right = getTreeNode(7)
tree.root.right.right = getTreeNode(1)
tree.root.right.right.left = getTreeNode(5)
// Print triple order
// ----------------------------------
// 4 -4 2 2 2 -4 3 6 9 9 9 6 6 3 8 8 ..
// 8 3 -4 4 7 7 1 5 5 5 1 1 7 4
tree.tripleOrder(tree.root)
}``````

Output

`` 4 -4 2 2 2 -4 3 6 9 9 9 6 6 3 8 8 8 3 -4 4 7 7 1 5 5 5 1 1 7 4``

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.