Amazon Interview Question
Country: United States
4 Answers
void Func(tNode **node){
if(*node!=NULL){
Func(&(*node)->pLeft);
tNode *temp;
temp = (*node)->pLeft;
(*node)->pLeft= (*node)->pRight;
(*node)->pRight = temp;
Func(&(*node)->pLeft);
}
}
will create a mirror image.
The above code will just swap root node's Left and Right child.
thank u guys bt
Let the input given be
98,15,100,10,78,120,5,12,96,110
What would be the output of the following code snippet?
int main(void)
{
tree *bT = new tree;
int i = 10;
int data;
while(i--){
std::cout<<"Enter the node"<<std::endl;
std::cin>>data;
bT->InsertNode(bT->GetRootNode(), data);
}
bT->Func(bT->GetRootNode());
bT->InsertNode(bT->GetRootNode(), 99);
bT->Func(bT->GetRootNode());
bT->traverse(bT->GetRootNode());
}
// insert() is simple bst insert and traverse() is postorder traversal
It's not mirror image.
- words&lyrics July 31, 2012