Mirror Binary Tree Nodes
Given the root node of a binary tree, swap the left and right children for each node.
We'll cover the following...
Statement
Given the root node of a binary tree, swap the left and right children for each node, such that the binary tree becomes a mirror image of itself.
Example
The below example shows what the mirrored binary tree looks like:
Sample input
The input list below represents the level-order traversal of the original binary tree:
[100, 50, 200, 25, 75, 350]
Expected output
The sequence below represents the in-order traversal of the mirrored binary tree:
350, 200, 100, 75, 50, 25
Try it yourself
Note: The binary tree node’s class has members
left
andright
to store references to other nodes, along with the memberdata
to hold the node’s value.
main.cpp
BinaryTree.cpp
BinaryTreeNode.cpp
#include <iostream>#include "BinaryTree.cpp"using namespace std;void MirrorBinaryTree(BinaryTreeNode* node) {// TODO: Write - Your - Code}