boolean areMirrorTrees(BinaryTree a, BinaryTree b) { if (a == null && b == null) { return true; } if (a == null || b == null) { return false; } return a.data == b.data && areMirrorTrees(a.left, b.right) && areMirrorTrees(a.right, b.left); }
Inorder traversal of the first tree will be: 3, 4, 5, 6, 7, 8, 9, 10, 12, 13.
Inorder traversal of the second tree will be: 13, 12, 10, 9, 8, 7, 6, 5, 4, 3.
Inorder traversal of the second tree will be: 13, 12, 10, 9, 8, 7, 6, 5, 4, 3.
video explanation Mirror of Tree's both method and code is discussed : www.youtube.com/watch?v=P40mZ4lWh-A
ReplyDelete