#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<limits.h>
struct tree
{
int data;
struct tree* left;
struct tree* right;
};
typedef struct tree tree;
tree* create(int data)
{
tree* temp=(tree*)malloc(sizeof(tree));
temp->data=data;
temp->left=NULL;
temp->right=NULL;
return temp;
}
tree* insertion(tree* root,int data)
{
if(root==NULL)
{
root=create(data);
return root;
}
else
{
if(root-> data > data)
{
root->left=insertion(root->left,data);
}
else
{
root->right=insertion(root->right,data);
}
return root;
}
}
tree* preorder(tree* root)
{
if(root==NULL)
{
return NULL;
}
printf(" %d ",root->data);
preorder(root->left);
preorder(root->right);
}
void Print_node(tree* root, int space)
{
if (root == NULL)
return;
space += 5;
Print_node(root->right, space);
printf("\n");
for (int i = 5; i < space; i++)
printf(" ");
printf("%d\n", root->data);
Print_node(root->left, space);
}
int Totalsum(tree* root)
{
if(root==NULL)
{
return 0;
}
return root->data+Totalsum(root->left)+Totalsum(root->right);
}
int countnode(tree* root)
{
if(root==NULL)
{
return 0;
}
return 1+countnode(root->left)+countnode(root->right);
}
int internalnodes(tree* root)
{
if(root==NULL)
{
return 0;
}
else
{
if(root->left==NULL && root->right==NULL)
{
return 0;
}
return root->data+internalnodes(root->left)+internalnodes(root->right);
}
}
int leafsum(tree* root)
{
if(root==NULL)
{
return 0;
}
int sum=0;
if(root->left==NULL && root->right==NULL)
{
sum=sum+root->data;
}
sum=sum+leafsum(root->left);
sum=sum+leafsum(root->right);
return sum;
}
int Evensum(tree* root)
{
if(root==NULL)
{
return 0;
}
int sum=0;
if((root->data)%2==0)
{
sum=sum+root->data;
}
sum=sum+Evensum(root->left);
sum=sum+Evensum(root->right);
return sum;
}
int oddsum(tree* root)
{
if(root==NULL)
{
return 0;
}
int sum=0;
if((root->data)%2!=0)
{
sum=sum+root->data;
}
sum=sum+oddsum(root->left);
sum=sum+oddsum(root->right);
return sum;
}
int findmaxvalue(tree* root)
{
if(root==NULL)
{
return 0;
}
int left=findmaxvalue(root->left);
int right=findmaxvalue(root->right);
int maximum=root->data;
if(left> maximum)
{
maximum=left;
}
if(right>maximum)
{
maximum=right;
}
return maximum;
}
int findminivalue(tree* root)
{
if(root==NULL)
{
return INT_MAX;
}
int left=findminivalue(root->left);
int right=findminivalue(root->right);
int minimum=