How to implement int getheight to find depth of a binary sea

How to implement int getheight() to find depth of a binary search tree? I need cpp code. Also, note thst there is no argument for input parameter to getheight.
How to implement int getheight() to find depth of a binary search tree? I need cpp code. Also, note thst there is no argument for input parameter to getheight.

Solution

struct BinaryTree{
private:
       int data;
       BinaryTree *left;
       BinaryTree *right;
   public:
       int getHeig
};

class BTree{
   BinaryTree *root;
   int Height(BinaryTree *root);
   public:
       void getHeight();
};

int BTree::Height(BinaryTree *root){
   int leftheight,rightheight;
   if(root == NULL)
       return 0;
   else{
       leftheight = Height(root->left);
       rightheight = Height(root->right);
       if(leftheight >= rightheight)
           return leftheight + 1;
       else
           return rightheight + 1;

   }
}

int BTree::getHeight(){
   return Height(root);
}

How to implement int getheight() to find depth of a binary search tree? I need cpp code. Also, note thst there is no argument for input parameter to getheight.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site