Question: PS: PLEASE MAKE THE PROGRAM BELOW LIKE THE EXAMPLE FORMAT #include #include #include struct bnode{ int val; // value at node struct bnode* lchild; //

PS: PLEASE MAKE THE PROGRAM BELOW LIKE THE EXAMPLE FORMAT

#include

#include

#include

struct bnode{

int val; // value at node

struct bnode* lchild; // left child

struct bnode* rchild; // right child

};

typedef struct bnode* bptr; // declaring struct node * as bptr

bptr creatNode(int val){ // function for creating newnode of type bnode

bptr n = (bptr) malloc(sizeof(struct bnode));

n->val=val;

n->lchild=NULL;

n->rchild=NULL;

return(n);

}

void print(bptr node) //inorder traversal of binary tree

{

if (node == NULL)

{printf("NULL ") ; return; }

else

{ printf("%d ", node->val);

print(node->lchild);

print(node->rchild);}

}

void print_left_right(bptr node){ // printing left and right subtree of every node in LRD formate

if(node==NULL)

{return;} // if child is not their assign -1 for NULL node

else{

print_left_right(node->lchild);

print_left_right(node->rchild);

printf("value of left subtree of node %d is :-",node->val); // printing left and right subtree of evry node;

print(node->lchild);

printf(" ");

printf("value of right subtree of node %d is :-",node->val);

print(node->rchild);

printf(" ");

}

}

void Preorder(bptr node) // preorder traversal of binary tree

{

if(node == NULL)

return;

else{

printf("%d ", node->val);

Preorder(node->lchild);

Preorder(node->rchild);}

}

void Inorder(bptr node) //inorder traversal of binary tree

{

if (node == NULL)

return;

else

{

Inorder(node->lchild);

printf("%d ", node->val);

Inorder(node->rchild); }

}

void Postorder(bptr node) // psotorder traversal of binary tree

{

if (node == NULL)

return;

else{

Postorder(node->lchild);

Postorder(node->rchild);

printf("%d ", node->val); }

}

int main()

{

bptr root = creatNode(3); // given root

root->lchild = creatNode(6); // given left subtre

root->lchild->lchild = creatNode(1);

root->lchild->rchild = creatNode(5);

root->rchild = creatNode(7); // given right subtree

root->rchild->lchild = creatNode(2);

printf("All the left and right subtree are in DLR formate ");

print_left_right(root);

printf(" root is %d :- ",root->val );

printf(" ");

printf(" Preorder traversal is ");

Preorder(root);

printf(" Inorder traversal is ");

Inorder(root);

printf(" Postorder is ");

Postorder(root);

printf(" ");

return 0;

}

THIS IS THE EXAMPLE

Example

Input:

(A,B,E) (this means A is the root, B is the left subtree, and E is the right subtree)

(B,C,null) (this means B is the root, C is the left subtree, and there is no right subtree)

(C,null,D)

(E,F.H)

(F,null ,G)

(H, I , J )

OUTPUT:

Node L-Subtree R-Subtree

A B E

B C null

C null D

E F H

F null G

H I J

Root of the Tree: A

Preorder Traversal: A B C D E F G H I J

Inorder Traversal: C D B A F G E I H J

Postorder Traversal: D C B G F I J H E A

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!