Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int tree :: depth(tree_node *root)
- {
- if(!root)
- return 0;
- return 1+my_max(depth(root->left),depth(root->right));
- }
- int tree :: count_on_lvl(tree_node *root, int level)
- {
- int count=0;
- if(!root)
- return 0;
- if(level == 0)
- return 1;
- count+=count_on_lvl(root->left, level-1);
- count+=count_on_lvl(root->right, level-1);
- return count;
- }
- int tree :: count_on_k_lvl(tree_node *root, int k)
- {
- int count_lvl=depth(root), count=0;
- if(!root || k > count_lvl)
- return 0;
- count = count_on_lvl(root, k);
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement