Given a binary tree, connect the nodes that are at same level.
Structure of the given Binary Tree node is like following.
Initially, all the nextRight pointers point to garbage values. Your function should set these pointers to point next right for each node.
10 10 ------> NULL
/ \ / \
3 5 => 3 ------> 5 --------> NULL
/ \ \ / \ \
4 1 2 4 --> 1 -----> 2 -------> NULL
The input contains T, denoting number of testcases. For each testcase there will be third lines. The first line contains number of edges. The second line contains relation between nodes. The second line contains two nodes and a character separated by space. The first node denotes data value, second node denotes where it will be assigned to the previous node which will depend on character 'L' or 'R' i.e. the 2nd node will be assigned as left child to the 1st node if character is 'L' and so on. The first node of second line is root node. The struct or class Node has a data part which stores the data, pointer to left child and pointer to right child. There are multiple test cases. For each test case, the function will be called individually.
For each testcase, in a new line, print the level order and inorder traversals.
You don't have to take input. Complete the function connect() that takes node as parameter and connects the nodes at same level. The printing is done by the driver code.