Write a function to find the depth of a binary tree.
Answers were Sorted based on User's Feedback
Answer / shabana parveen
int depth(treenode *p)
{
if(p==NULL)return(0);
if(p->left){h1=depth(p->left);}
if(p=>right){h2=depth(p->right);}
return(max(h1,h2)+1);
}
dis is really a good program.
actually it is so efficient in time and to the point that i
hav copied it again from neetu katiyar.
Is This Answer Correct ? | 31 Yes | 34 No |
Answer / mohan p
int depth(treenode *p)
{
if(p==NULL)return(0);
if(p->left){h1=depth(p->left);}
if(p=>right){h2=depth(p->right);}
return(max(h1,h2)+1);
}
The above code will return the number of nodes in the
longest path from root to the leaf. So subtracting with -1
will give the depth of the tree. Depth of the tree is the
distance from root to the deepest leaf.
Is This Answer Correct ? | 13 Yes | 16 No |
Answer / sameera.adusumilli
int Depth(struct Node*node,int level)
{
if(Node!=NULL)
{
if(level<depth)
depth=level;
Depth(Node->leftchild,level+1);
Depth(Node->rightchild,level+1);
}
return(depth);
}
Is This Answer Correct ? | 52 Yes | 93 No |
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }
main() { main(); }
write a program in c to merge two array
main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error
main() { int i, j, *p; i = 25; j = 100; p = &i; // Address of i is assigned to pointer p printf("%f", i/(*p) ); // i is divided by pointer p } a. Runtime error. b. 1.00000 c. Compile error d. 0.00000
How to count a sum, when the numbers are read from stdin and stored into a structure?
how to swap 3 nos without using temporary variable
respected sir, i did my MCA in 2013 when i am going to attend to an interview i was asked about my project how will i explain my project could please help me in this and my project title is "Social Networking Site For Social Responsibility"
void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }
Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list)
3 Answers Disney, Google, ZS Associates,
#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }
Write a C program to print ‘Campus Force training’ without using even a single semicolon in the program.