- Backtracking, Linked List, Linked Lists, Preorder Traversal, Recursion, Tree, tree-traversal

Find direction of path followed from root by a linked list in a Binary Tree

#include using namespace std;  struct ListNode {    int data;    ListNode* next;    ListNode(int data)    {        this->data = data;        this->next = NULL;    }};  struct TreeNode {    TreeNode* left;    TreeNode* right;    int val;      TreeNode(int x)        : left(NULL), right(NULL), val(x)    {    }};  ListNode* makeList(int arr[], int n){    ListNode* h = NULL;    ListNode* root;    for (int i = 0; i < n; i++) {        int data = arr[i];        ListNode* node = new ListNode(data);          if (h == NULL) {            h = node;            root = h;        }        else {            root->next = node;            root = node;        }    }    return h;}  TreeNode* build_tree(int nodes[], int n){    TreeNode* root = new TreeNode(nodes[0]);    queue q;    bool is_left = true;    TreeNode* cur = NULL;    q.push(root);      for (int i = 1; i < n; i++) {        TreeNode* node = NULL;        if (nodes[i] != '#') {            node = new TreeNode(nodes[i]);            q.push(node);        }          if (is_left) {            cur = q.front();            q.pop();            cur->left = node;            is_left = false;        }        else {            cur->right = node;            is_left = true;        }    }      return root;}  bool findPath(TreeNode* root, ListNode* head,              vector& path){        if (root == NULL) {        return false;    }                  if (root->val != head->data)        return false;          if (root->left == NULL        and root->right == NULL        and head->next == NULL) {        return true;    }          path.push_back(‘L’);          if (findPath(root->left,                 head->next, path))        return true;              path.pop_back();          path.push_back(‘R’);          if (findPath(root->right,                 head->next, path))        return true;              path.pop_back();      return false;}  void find(TreeNode* root, ListNode* head){    vector path;              findPath(root, head, path);              if (path.size() == 0) {        cout