Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! Code below ``` #include #include struct Node { int val; struct Node * left; struct Node * right; }; struct Node * create_node(char

Please help! Code below

image text in transcribed```

#include  #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); } 

```

Problem 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 treel ) doesn't work, so rewrite it so that it does. Then upload it into laulima

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions

Question

7-16 Compare Web 2.0 and Web 3.0.

Answered: 1 week ago