Tree Programs
Tree Programs
#include "binary.h"
if(root!=NULL)
countNode(root->left);
count++;
countNode(root->right);
return count;
b=a;
a=root;
if(a==NULL)
return b->data;
getMin(root->left);
struct node*a=NULL,*b=NULL;
a=b;
b=root;
if(b==NULL)return a->data;
getMax(root->right);
Tree Mirror
#include "binary.h"
// Convert to Mirror
if(root==NULL)
return;
root->left=root->right;
root->right=a;
mirror(root->left);
mirror(root->right);
Tree Levelorder
#include "binary.h"
// Levelorder Operation
if(root==NULL)return 0;
int lh=height(root->left);
int rh=height(root->right);
return (lh>rh)?lh+1:rh+1;
if(root==NULL)return ;
if(l==1)printf("%d ",root->data);
else if(l>1){
printLevelOrder(root->left,l-1);
printLevelOrder(root->right,l-1);
for(int i=1;i<=h;i++)printLevelOrder(root,i);
if(root==NULL)
return 0;
return root->data;
return sumOfLeaf(root->left)+sumOfLeaf(root->right);
BST - Identical
#include "binary.h"
return 1;
if(root1==NULL || root2==NULL)
return 0;