The structure of Node of a Binary Tree and Doubly linked list are same.
struct Node { int data; Node* left; Node* right; } Structure of Node of a Binary Tree |
struct Node { int data; Node* previous; Node* next; } Structure of Node of a Doubly linked list |
If we treat left pointer as previous and right pointer as next, we can use the Node of a Binary Tree to represent node of a Doubly linked list or vice-versa.
Given a binary tree, modify the pointers in each node of the tree so that they represent a Doubly linked. Order of the nodes in DLL should be same as that in the in-order traversal.
If the Input Binary tree is as below
then the function should modify pointers in the nodes, as shown below and return the head pointer.