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

why we wont use '&' sing in aceesing the string using scanf

1777


How can you tell whether two strings are the same?

826


What are the complete rules for header file searching?

666


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

651


How can I make it pause before closing the program output window?

576






Explain how can I prevent another program from modifying part of a file that I am modifying?

633


Can a pointer point to null?

582


What kind of structure is a house?

551


What is #include cctype?

576


How can I sort a linked list?

633


Explain what is a program flowchart and explain how does it help in writing a program?

643


Give the rules for variable declaration?

669


What is the difference between %d and %i?

592


Define VARIABLE?

686


What is the return type of sizeof?

588