Microsoft Interview Question
Software Engineer in TestsCountry: United States
I presume that each node has a pointer to its left child and the left child has a pointer to its sibling. Thus rightchild(x) is obtained by leftchild(x)->sibling. What happens if a node has a right child only? How is this expressed?
we can define a struct
strcut BST
{
BST Left;
int data;
BST Right;
BST LeftToRightLink
}
void INSERT (BST parent , BST node , int iData)
{
BST Temp = node;
parent = node;
if( temp == NULL)
{
temp = new BST();
temp.Left = NULL;
temp.data = iData;
temp.Right = NULL;
temp.LeftToRightLink = parent
return;
}
//Use recursion
if(iData > Temp.Data)
INSERT (Parent , Temp.Right)
else
INSERT (Parent , Temp.Left)
}
And what kind of program should I write about this binary tree?
- eugene.yarovoi April 17, 2012