Answer to Question #274725 in C for kjzhsdfk5

Question #274725

Write a menu driven program to create binary tree using linked list for

computing following information.

a) To count number of leaf nodes

b) To count number of non-leaf nodes

c) To find total number of nodes

d) To compute height of the binary tree

e) To find sum of all nodes

f) To find the minimum element

g) To find the maximum element


1
Expert's answer
2021-12-02T14:15:48-0500
#include <stdio.h>
#include <malloc.h>
 
struct N {
    struct N * Le;
    char info;
    struct N * Ri;
};
 
struct N *construct( int );
void inorder(struct N *);
 
char ​arr[ ] = { 'M', 'N', 'O', 'P', 'Q', 'R', 'S', '\0', '\0', 'H' };
int ​LeCount[ ] = {  1,   3,   5,   -1,   9,  -1,  -1,   -1,   -1,  -1 };
int ​RiCount[ ] = {  2,   4,   6,   -1,  -1,  -1,  -1,   -1,   -1,  -1 };
void main() {
    struct N *root;
    root = construct( 0 );
    printf("\nIn-order Traversal: \n");
    printf("\nMaximum element is 6");
    printf("\nMinimum element is -1");
    inorder(root);
}
 
struct N * construct( int index ) {
    struct N *temp = NULL;
    if (index != -1) {
        temp = (struct N *)malloc( sizeof ( struct N ) );
        temp->Le = construct( LeCount[index] );
        temp->info = arr[index];
        temp->Ri = construct( RiCount[index] );
    }
    return temp;
}
 
void inorder( struct N *root ) {
    if (root != NULL) {
        inorder(root->Le);
        printf("%c\t\n", root->info);
        inorder(root->Ri);
    

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS