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 |
WAP to display 1,2,3,4,5........N
main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }
Write a c program to search an element in an array using recursion
main() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }
main(int argc, char **argv) { printf("enter the character"); getchar(); sum(argv[1],argv[2]); } sum(num1,num2) int num1,num2; { return num1+num2; }
What is the output for the following program main() { int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }
Find your day from your DOB?
15 Answers Accenture, Microsoft,
write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"
Write a program that find and print how many odd numbers in a binary tree
Hi, i have a project that the teacher want a pyramid of numbers in C# or java...when we click a button...the pyramid should be generated in a listbox/or JtextArea...and the pyramid should have the folowing form: 1 232 34543 4567654 567898765 67890109876 7890123210987 890123454321098 90123456765432109 0123456789876543210 Plz help with codes...didn't find anything on the net.
could you please send the program code for multiplying sparse matrix in c????
What are segment and offset addresses?