Answered step by step
Verified Expert Solution
Question
1 Approved Answer
*** NEED THE CODE IN C LANGUAGE *** #include #include struct Node { int val; struct Node * left; struct Node * right; }; struct
*** NEED THE CODE IN C LANGUAGE ***
#includeProblem 1 (1 pt). The attached program createTree.c has the following function that creates the binary tree from its pre-order and in-order lists struct Node create_tree(int pre_order[], int pre_first, int pre_last, int in_order[], int in_first, in_last); preorder[]: pre-order list that starts at index pre_first and ends at index pre_last inorder[]: in-order list that starts at index in_first and ends at index in_last The test case in the program: pre-order list: Y,F,H,Z,B,G,C,D,Q,A,K,M in-order list: Z,H,B,F,G,C,Y,D,K,A,M,Q Function create_tree( ) doesn't work, so rewrite it so that it does#include struct Node { int val; struct Node * left; struct Node * right; }; struct Node * create_node(char val); void destroy_node(struct Node * root); void destroy_tree(struct Node * root); void list_preorder(struct Node * root); void list_inorder(struct Node * root); struct Node * create_tree(char pre_order[], int pre_first, int pre_last, char in_order[], int in_first, int in_last) { return NULL; } void main() { char pre_order[12] = {'Y','F','H','Z','B','G','C','D','Q','A','K','M'}; char in_order[12] = {'Z','H','B','F','G','C','Y','D','K','A','M','Q'}; struct Node * root= create_tree(pre_order,0,11,in_order,0,11); printf("Pre-order: "); list_preorder(root); printf(" "); printf("In-order: "); list_inorder(root); printf(" "); destroy_tree(root); } struct Node * create_node(char val) { struct Node * node = (struct Node *) malloc(sizeof(struct Node)); node->val = val; node->left = NULL; node->right = NULL; return node; } void destroy_node(struct Node * root) { free(root); } void destroy_tree(struct Node * root) { if (root!=NULL) { destroy_tree(root->left); destroy_tree(root->right); destroy_node(root); } } void list_preorder(struct Node * root) { if (root==NULL) return; printf(" %c",root->val); list_preorder(root->left); list_preorder(root->right); } void list_inorder(struct Node * root) { if (root==NULL) return; list_inorder(root->left); printf(" %c",root->val); list_inorder(root->right); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started