Mirror a Binary Tree
📖 Scenario: You are working with a simple binary tree structure used in many applications like file systems or decision trees. Sometimes, you need to create a mirror image of this tree, flipping it left to right.
🎯 Goal: Build a program that creates a binary tree, then writes a function to mirror it by swapping left and right children at every node, and finally prints the mirrored tree in order.
📋 What You'll Learn
Create a binary tree with exactly 5 nodes with these values: 1 (root), 2 (left child of root), 3 (right child of root), 4 (left child of node 2), 5 (right child of node 2)
Create a function called
mirror that takes a pointer to the root node and swaps its left and right children recursivelyCreate a function called
inorder that prints the tree nodes in inorder traversal separated by spacesPrint the inorder traversal of the mirrored tree
💡 Why This Matters
🌍 Real World
Mirroring trees is useful in graphics, image processing, and reversing decision trees for analysis.
💼 Career
Understanding tree manipulations is important for software engineers working with data structures, algorithms, and system design.
Progress0 / 4 steps