Thursday, 2 August 2012

C program to determine the number of elements in a tree (or) size of the tree

//address of root node of the tree is passed to this function

int treeSize(struct node* node) 
{ 
if (node==NULL) 
{ 
return 0; 
} 
else 
{ 
return (treeSize(node->left) + treeSize(node->right) + 1); 
} 
}

No comments:

Post a Comment