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

How are pointers declared in c?

603


What is the newline escape sequence?

596


Explain continue keyword in c

594


Explain what is gets() function?

641


Explain 'bus error'?

570






What are the Advantages of using macro

694


What is the acronym for ansi?

640


What is c method?

542


What is #define used for in c?

618


Can you please explain the difference between syntax vs logical error?

702


Explain pointers in c programming?

640


Can you please explain the difference between strcpy() and memcpy() function?

609


What does s c mean in text?

625


What is the difference between ā€˜gā€™ and ā€œgā€ in C?

2691


What is indirection?

661