Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. int tree :: depth(tree_node *root)
  2. {
  3.     if(!root)
  4.         return 0;
  5.     return 1+my_max(depth(root->left),depth(root->right));
  6. }
  7.  
  8. int tree :: count_on_lvl(tree_node *root, int level)
  9. {
  10.     int count=0;
  11.     if(!root)
  12.         return 0;
  13.     if(level == 0)
  14.         return 1;
  15.     count+=count_on_lvl(root->left, level-1);
  16.     count+=count_on_lvl(root->right, level-1);
  17.     return count;
  18. }
  19.  
  20. int tree :: count_on_k_lvl(tree_node *root, int k)
  21. {
  22.     int count_lvl=depth(root), count=0;
  23.     if(!root || k > count_lvl)
  24.         return 0;
  25.     count = count_on_lvl(root, k);
  26.     return count;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement