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 |
Can the sizeof operator be used to tell the size of an array passed to a function?
actually i have 2 years teaching experience as computer faculty but now i am a DBA but when i go for interview many peoples asked me why i left my teaching profession and why i want to come in this field kindly give me the proper answer of this queston
What are the types of functions in c?
An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above
program that accepts amount in figures and print that in words
2 Answers Infosys, Lovely Professional University, Wipro,
What is difference between static and global variable in c?
What is the size of empty structure in c?
What is the method to save data in stack data structure type?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
How many types of errors are there in c language? Explain
Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon
What are predefined functions in c?