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 |
pls anyone can help me to write a code to print the values in words for any value.Example:1034 to print as "one thousand and thirty four only"
#include<stdio.h> main() { FILE *ptr; char i; ptr=fopen("zzz.c","r"); while((i=fgetch(ptr))!=EOF) printf("%c",i); }
main() { extern int i; i=20; printf("%d",sizeof(i)); }
main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }
char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }
main() { int a[10]; printf("%d",*a+1-*a+3); }
program to find the roots of a quadratic equation
14 Answers College School Exams Tests, Engineering, HP, IIIT, Infosys, Rajiv Gandhi University of Knowledge Technologies RGUKT, SSC,
main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); } } a. 512, 256, 128, 64, 32 b. 256, 128, 64, 32, 16 c. 128, 64, 32, 16, 8 d. 64, 32, 16, 8, 4
main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }
main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); } a. Runtime error. b. I am OK c. Compile error d. I am O
print numbers till we want without using loops or condition statements like specifically(for,do while, while swiches, if etc)!