fork download
  1. // Following is the Binary Tree node structure
  2. /**************
  3. class BinaryTreeNode {
  4.   public :
  5.   T data;
  6.   BinaryTreeNode<T> *left;
  7.   BinaryTreeNode<T> *right;
  8.  
  9.   BinaryTreeNode(T data) {
  10.   this -> data = data;
  11.   left = NULL;
  12.   right = NULL;
  13.   }
  14. };
  15. ***************/
  16.  
  17. int solve(BinaryTreeNode<int>* root, int M){
  18. // Write your code here
  19. int level = 0;
  20. if(root == NULL){
  21. return 0;
  22. }
  23. if(root->data == M ){
  24. return level+1;
  25. }
  26. if(root->left!=NULL){
  27. solve(root->left, M);
  28. level++;
  29. }
  30. else{
  31. solve(root->right, M);
  32. level++;
  33. }
  34. // return level;
  35.  
  36. }
  37.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:17:11: error: ‘BinaryTreeNode’ was not declared in this scope
 int solve(BinaryTreeNode<int>* root, int M){
           ^~~~~~~~~~~~~~
prog.cpp:17:26: error: expected primary-expression before ‘int’
 int solve(BinaryTreeNode<int>* root, int M){
                          ^~~
prog.cpp:17:38: error: expected primary-expression before ‘int’
 int solve(BinaryTreeNode<int>* root, int M){
                                      ^~~
prog.cpp:17:43: error: expression list treated as compound expression in initializer [-fpermissive]
 int solve(BinaryTreeNode<int>* root, int M){
                                           ^
stdout
Standard output is empty