Write code for finding depth of tree

Answer Posted / om

struct tree //creating structure

{

int data; //data field of node

struct tree *lchild,*rchild;//left child & right child of node

};


//for depth calculation

int depth(struct tree *p)

{

int l,r;

if(p!=NULL)

{

l=depth(p->lchild);

r=depth(p->rchild);

return (1+((l>r)?l:r));

}

return -1;

}

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are preprocessor directives?

817


write a c program to print the next of a particular no without using the arithmetic operator or looping statements?

3514


Explain how do you convert strings to numbers in c?

812


What are enumerated types?

840


Can we declare variable anywhere in c?

719


What is the size of enum in c?

833


Find MAXIMUM of three distinct integers using a single C statement

818


What is the argument of a function in c?

770


What is the purpose of the statement: strcat (S2, S1)?

841


What is the scope of static variables in c language?

828


What is difference between %d and %i in c?

895


What does main () mean in c?

850


Tell us bitwise shift operators?

797


Is it valid to address one element beyond the end of an array?

912


The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none

972