Question: Complete source.cpp below #include #include Node.h using namespace std; /* HELPER FUNCTIONS */ /* Function to find index of value in arr[start...end] The function assumes

Complete source.cpp below

#include  #include "Node.h" using namespace std; /* HELPER FUNCTIONS */ /* Function to find index of value in arr[start...end] The function assumes that value is present in in[] */ int search(char arr[], int strt, int end, char value) { for (int i = strt; i <= end; i++) { if (arr[i] == value) return i; } } /* Recursive function to construct binary tree of size len from Inorder traversal in[] and Preorder traversal pre[]. You can create a node and recursively find the left node and right node of that node For initial call (in the main function), inStr was set to 0 and inEnd set to len-1 The function doesn't need to do any error checking for cases where inorder and preorder do not form a tree */ Node* buildTree(char in[], char pre[], int inStrt, int inEnd) { // This is the static variable. // It is like that this line just run once // At each recurion call, it does not reset to 0, so you can keep track of whatever index you want static int preIndex = 0; /****************TO DO **************** } /* This funtcion is here just to test buildTree() */ void printInorder(Node* node) { if (node == NULL) return; /* first recur on left child */ printInorder(node->left); /* then print the data of node */ cout<< node->data << ' ' ; /* now recur on right child */ printInorder(node->right); } /* Driver program to test above functions */ int main() { char in[] = { 'D', 'B', 'E', 'A', 'F', 'C' }; char pre[] = { 'A', 'B', 'D', 'E', 'C', 'F' }; int len = sizeof(in) / sizeof(in[0]); Node* root = buildTree(in, pre, 0, len - 1); /* Let us test the built tree by printing Insorder traversal */ cout << "correct solution is "< 

Node.h

#ifndef NODE_H #define NODE_H class Node { public: // We actually implement the constructor here, // in the header file (it's too little to "earn" a .cpp) Node(char n) { this->data = n; left = right = nullptr; } char data; Node* left; Node* right; }; #endif 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!