# Triple order traversal of a binary tree in typescript

Ts program for Triple order traversal of a binary tree. Here mentioned other language solution.

``````/*
TypeScript program for
Triple order traversal of a binary tree
*/
// Binary Tree node
class TreeNode
{
public data: number;
public left: TreeNode;
public right: TreeNode;
constructor(data: number)
{
// Set node value
this.data = data;
this.left = null;
this.right = null;
}
}
class BinaryTree
{
public root: TreeNode;
constructor()
{
// Set initial tree root
this.root = null;
}
public tripleOrder(node: TreeNode)
{
if (node != null)
{
// Print preorder node
console.log(" " + node.data);
// Visit left subtree
this.tripleOrder(node.left);
// Print inorder node
console.log(" " + node.data);
// Visit right subtree
this.tripleOrder(node.right);
// Print postorder node
console.log(" " + node.data);
}
}
public static main()
{
// Create new binary trees
var tree = new BinaryTree();
/*
4
/ \
/   \
-4     7
/ \     \
2   3     1
/ \   /
6   8 5
/
9
----------------------
Constructing binary tree

*/
tree.root = new TreeNode(4);
tree.root.left = new TreeNode(-4);
tree.root.left.right = new TreeNode(3);
tree.root.left.right.left = new TreeNode(6);
tree.root.left.right.left.left = new TreeNode(9);
tree.root.left.right.right = new TreeNode(8);
tree.root.left.left = new TreeNode(2);
tree.root.right = new TreeNode(7);
tree.root.right.right = new TreeNode(1);
tree.root.right.right.left = new TreeNode(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);
}
}
BinaryTree.main();
/*
file : code.ts
tsc --target es6 code.ts
node code.js
*/``````

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.