Binary Tree to CDLL
Submissions: 2088   Accuracy:

49.82%

  Difficulty: Medium
       

Given a Binary Tree (BT), convert it to a Circular Doubly Linked List(DLL) In-Place. The left and right pointers in nodes are to be used as previous and next pointers respectively in converted CDLL. The order of nodes in CDLL must be same as Inorder of the given Binary Tree. The first node of Inorder traversal (left most node in BT) must be head node of the CDLL.

Input:
The task is to complete the method which takes a arguments, root of Binary Tree.
The struct 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, this method will be called individually.

Output:
The function should return the head of CDLL.

Constraints:
1 <=T<= 100
1 <=Number of nodes<= 100
1 <=Data of a node<= 100

Example:
Input:

2
2
1 2 R 1 3 L
4
10 20 L 10 30 R 20 40 L 20 60 R
Output:
3 1 2 
2 1 3
40 20 60 10 30 
30 10 60 20 40

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: saksham seth


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.