Write a program to find the mirror image of a nary tree
Software QA/Tests Interview Questions from Microsoft
(Continued from previous question...)
Write a program to find the mirror image of a nary tree
Question:
Write a program to find the mirror image of a nary tree
maybe an answer:
Tnode MirrorTree(TNode tnode)
{
// Don't do anything if the number of children is less than one
if(tnode.Children.Count < 2) return tnode;
// else push the children into a stack and set that as children
List<TNode> children = tnode.Children;
List<TNode> stack = new List<TNode>;
foreach(TNode t in children){
stack.insertAt(0,MirrorTree(t));
}
t.Children = stack;
children = null;
return tnode;
}
(Continued on next question...)
Other Interview Questions
