int SizeOfBinaryTree(struct BinaryTreeNode *root) { if (root == NULL) { return 0; } else { return(SizeOfBinaryTree(root->left) + 1 + SizeOfBinaryTree(root->right)); } }
unsigned int SizeOfBinaryTree( TreeNode *root ) { if( !root ) { return 0; } return 1 + SizeOfBinaryTree( root->left ) + SizeOfBinaryTree( root->right ); }
int main() { TreeNode *root = NULL; InsertIntoTree( &root, 1 ); InsertIntoTree( &root->left, 2 ); InsertIntoTree( &root->right, 3 ); InsertIntoTree( &root->left->left, 4 ); // InsertIntoTree( &root->left->right, 5 ); InsertIntoTree( &root->right->left, 6 ); InsertIntoTree( &root->right->right, 7 ); printf("\n Size of Binary Tree is: %d. \n", SizeOfBinaryTree( root ) ); return 0; }