How to find depth of a Binary Tree in C Programming ?

# include<stdio.h> 
# include<malloc.h> 
typedef struct NODE 
{ 
    char Info; 
    struct NODE *Left_Child; 
    struct NODE *Right_Child; 
}ND; 
int depth = 0; 
void Output ( ND*, int ); 
int Depth (ND *, int ); 
ND *Create_Tree (char , ND *); 
void Output(ND *T, int Level) 
{ 
    int i; 
    if (T) 
    { 
        Output(T->Right_Child, Level+1); 
        printf("\n"); 
        for (i = 0; i < Level; i++) 
            printf("  "); 
        printf("%c", T->Info); 
        Output(T->Left_Child, Level+1); 
    } 
} 
int Depth (ND *Node, int Level) 
{ 
    if (Node != NULL) 
    { 
        if (Level > depth) 
            depth = Level; 
        Depth (Node->Left_Child, Level + 1); 
        Depth (Node->Right_Child, Level + 1); 
    } 
    return (depth); 
} 
ND *  Create_Tree (char Info, ND *Node) 
{ 
    if (Node == NULL) 
    { 
        Node = (ND *) malloc(sizeof(ND)); 
        Node->Info = Info; 
        Node->Left_Child = NULL; 
        Node->Right_Child = NULL; 
        return (Node); 
    } 
    if (Info < Node->Info) 
        Node->Left_Child = Create_Tree (Info, Node->Left_Child); 
    else 
        if (Info > Node->Info) 
            Node->Right_Child = Create_Tree (Info, Node->Right_Child); 
    return(Node); 
} 
void main() 
{ 
    int Number = 0; 
    char Info ; 
    char choice; 
    int depth; 
    ND *T = (ND *) malloc(sizeof(ND)); 
    T = NULL; 
    printf("\n Input choice 'b' to break:"); 
    choice = getchar(); 
    while(choice != 'b') 
    { 
        fflush(stdin); 
        printf("\n Input information of the node: "); 
        scanf("%c", &Info); 
        T = Create_Tree(Info, T); 
        Number++; 
        fflush(stdin); 
        printf("\n Input choice 'b' to break:"); 
        choice = getchar(); 
    } 
    printf("\n Number of elements in the list is  %d", Number); 
    printf("\n Tree is \n"); 
    Output(T, 1); 
    depth = Depth(T, 0); 
    printf("\n Depth of the above tree is:  %d", depth); 
} 

Top