Write code for finding depth of tree
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / crispin
/*
* Simple tree node representation
*/
struct node_t {
struct node_t *left;
struct note_t *right;
};
/*
* Return the maximum depth of the tree given a pointer
* to its root node.
*/
unsigned int
tree_depth (node_t *root)
{
return (NULL == root) ? 0 :
MAX(tree_depth(root->left, root->right)+1);
}
| Is This Answer Correct ? | 3 Yes | 6 No |
What is default value of global variable in c?
string reverse using recursion
What is the difference between near, far and huge pointers?
Explain why can’t constant values be used to define an array’s initial size?
what is the difference between <stdio.h> and "stdio.h"
14 Answers Invendis, Kanbay, Mastek, MathWorks,
how does the for loop work actually..suppose for the following program how it ll work plz explain to me for(i=5;i>=0;i--) prinf(i--);
what is the difference between static variable and register variable?
main() { int arr[5]={23,67}; printf("%d%d%d",arr[2],arr[3],arr[4]); }
a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=? c) If in second stmt a=0 is replaced by -1, b=?
what are the compilation steps? ( i want inside the compiler )
What is an operator?
Explain demand paging.