Check out example codes for "Convert binary tree to a doubly linked list". It will help you in understanding the concepts better.

Code Example 1

#include <iostream> 
using namespace std; 
  
void BinaryTree2DoubleLinkedList(node *root, node **head) 
{ 
    if (root == NULL) return; 
    static node* prev = NULL; 
    BinaryTree2DoubleLinkedList(root->left, head); 
    if (prev == NULL) 
        *head = root; 
    else
    { 
        root->left = prev; 
        prev->right = root; 
    } 
    prev = root; 
    BinaryTree2DoubleLinkedList(root->right, head); 
} 
  

node* newNode(int data) 
{ 
    node* new_node = new node; 
    new_node->data = data; 
    new_node->left = new_node->right = NULL; 
    return (new_node); 
} 
  
void printList(node *node) 
{ 
    while (node!=NULL) 
    { 
        cout << node->data << " "; 
        node = node->right; 
    } 
}

Learn ReactJs, React Native from akashmittal.com