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 |
write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.
C program to read the integer and calculate sum and average using single dimensional array
What is dynamic memory allocation?
What is the difference between fread buffer() and fwrite buffer()?
What is || operator and how does it function in a program?
parkside's triangle.. create a program like this.. enter the size: 6 enter the seed: 1 output: 1 23 456 7891 23456 789123 sample2: enter the size: 5 enter the seed: 3 output: 3 45 678 9123 45678 parkside should not exceed 10 while its seed should only be not more than 9..
Difference between fopen() and open()?
What is the difference between getch() and getche()?
why we use "include" word before calling the header file. is there any special name for that include??????
without using arithmatic operator convert an intger variable x into x+1
pick out the odd one out of the following a.malloc() b.calloc() c.free() d.realloc()
Illustrate it summing the series 2+4+6+......to n terms using (i) while loop (ii) do-while loop