Interview Questions

Write a program to reverse pointers of a binary tree?.......

Microsoft Interview Questions and Answers


(Continued from previous question...)

129. Write a program to reverse pointers of a binary tree?.......

Question:
Write a program to reverse pointers of a binary tree?
Means to reverse all the pointers like at the beginning root points to children..The function should reverse pointers such that children point to root...


maybe an answer:


Small mistake in base condition root's child's pointers shd be to next.
Here is a code ....see if it is correct
void reverseTree(node*root , node* next){
if(root!=NULL){
reverseTree(root->left,root);
reverseTree(root->right,root);
root->left=next;
root->right=next;
}
}

Initial call will be reverseTree(root,NULL)

(Continued on next question...)

Other Interview Questions