C program to find the height of a binary search tree

Question:Write a C program to find the depth or height of a binary tree

Solution:
#include<stdio.h>
struct binarysearchtree
{
int data;
struct binarysearchtree* left;
struct binarysearchtree* right;
};
typedef struct binarysearchtree* tree;

int max(int a,int b)
{
if(a >=b)
return a;
else
return b;
}

int height(tree T)
{
if(T==NULL)
return 0;
else
{
int h1=height(T->left);
int h2=height(T->right);
return 1+max(h1,h2);
}
}



Click Here For More Questions

1 comment: