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 |
program to find which character is occured more times in a string and how many times it has occured? for example in the sentence "i love india" the output should be i & 3.
What is the purpose of the code, and is there any problem with it? unsigned int f( unsigned n ) { return –n & 7; }
What is string length in c?
What are the various types of control structures in programming?
What is the use of the sizeof operator?
1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. The Logic should be written in Data Structures?
What is the equivalent code of the following statement in WHILE LOOP format?
1. Write a program to reverse every second word in a given sentence.
Write a program in C to convert date displayed in gregorian to julian date
Can a file other than a .h file be included with #include?
write a programme to enter some number and find which number is maximum and which number is minimum from enterd numbers.
Explain what is the difference between a free-standing and a hosted environment?