Amazon Interview Question
Software Engineer / Developersstruct tree
{
int data;
struct tree *left;
struct tree *right;
};
int depth = 0;
Depth(struct node *Root)
{
int Level;
if(Root == NULL) return;
Depth(Root->left,Level + 1);
Depth(Root->right,Level + 1);
if(depth < Level)
{
depth = Level;
}
}
main()
{
struct tree *Root;
.........
........
Some code for tree creation
.........
.........
Depth(Root,0);
printf("\n Depth of the tree is %d",depth);
}
Yes... Thanks
- Abhishek February 03, 2010