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 |
Study the Following Points: a.One Cannot Take the address of a Bit Field b.bit fields cannot be arrayed c.Bit-Fields are machine Dependant d.Bit-fields cannot be declared as static 1. Which of the Following Statements are true w.r.t Bit- Fields A)a,b&c B)Only a & b C)Only c D)All
Why do we need a structure?
int main(){ float f=8.0; if(f==8.0) printf("good"); else printf("bad"); } what is the answere and explain it?
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
What are the advantages of using new operator as compared to the function malloc ()?
Where static variables are stored in c?
What is the maximum no. of arguments that can be given in a command line in C.?
write a pgm to print 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1
What does main () mean in c?
What is a program flowchart?
Can static variables be declared in a header file?
What is wrong with this initialization?