This will be a long post, including many questions solved from geeksforgeeks. I will continue to develop this with time. please follow regularly to see more solutions.
write a Function to print the sum of all leaf nodes:
int sumLeaf(Node* root){
int sum=0;
if(root==NULL)
{return 0;}
else
{
if(root->left==NULL && root->right==NULL)
{
sum+=root->data;
}
else
{ if(root->left!=NULL && root->right!=NULL)
{sum=sumLeaf(root->left)+sumLeaf(root->right);}
if(root->left!=NULL && root->right==NULL)
{sum=sumLeaf(root->left);}
if(root->right!=NULL && root->left==NULL)
{sum=sumLeaf(root->right);}
}
}
return sum;
}
write a Function to print the minimum element in a binary search tree:
int Minvalue(Node* root){
int data;
if(root->left!=NULL)
{
root=root->left;
}
else
{
data=root->data;
}
return data;
}
Comments
Post a Comment