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 c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b)); } a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above
4 Answers Corporate Society, HCL,
#include<stdio.h> main() { register i=5; char j[]= "hello"; printf("%s %d",j,i); }
Under linux environment can u please provide a c code for computing sum of series 1-2+3-4+5......n terms and -1+2-3+4-5...n terms..
How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?
main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i;
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.
void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }
Given n nodes. Find the number of different structural binary trees that can be formed using the nodes.
16 Answers Aricent, Cisco, Directi, Qualcomm,
how to check whether a linked list is circular.
main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024
main(){ int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y) printf("hello"); }