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 |
Explain how do I determine whether a character is numeric, alphabetic, and so on?
what is dangling pointer?
Do array subscripts always start with zero?
what is the use of bitfields & where do we use them?
how can i include my own .h file EX:- alex.h like #include<alex.h>, rather than #include"alex.h"
What is the purpose of sprintf?
What does != Mean in c?
How are portions of a program disabled in demo versions?
c program to compute Income tax and Net Salary for its employees. The company offers tax relief of Kshs. 650 for single employees and Kshs. 1,100 for married employees. The relief will be deducted from the Gross salary, to give the taxable income. This will be computed at the following rates: [10mks] Taxable Income Rate (%) <5000 0 5000-19999 6 20000-36999 9 37000 and above 16
What is the code for 3 questions and answer check in VisualBasic.Net?
helllo sir give me some information of the basic information the c as printf ,scanf , %d ,%f and why is the main use of these.
what is the difference between char * const and const char *?