Is This a Binary Search Tree?

  • + 1 comment

    I also did the same but some test cases are not working .Here my code- bool func(vector v) { int count=0; for(int i=0;i v; if(root==NULL) return true; if(root!=NULL) { checkBST(root->left); v.push_back(root->data); checkBST(root->right); } return func(v);

    }

    • + 0 comments

      You want this...

          static int min = -1;
          static boolean flag = true;
      
          public static void inOrder(Node root){ 
      
              if(root.left != null){
                  inOrder(root.left);
              }
              if(root.data <= min){
                  flag = false;
              }
              min = root.data;
              if(root.right != null){
                  inOrder(root.right);
              }
          }
          
          boolean checkBST(Node root) {
              inOrder(root);
              return flag;       
          }