Tree/invert_tree library

🌳 Tree Inverter (Mirror Tree)

Inverts a binary tree by swapping left and right children recursively. Returns the root of the inverted tree.

Time complexity: O(n) where n is the number of nodes Space complexity: O(h) where h is the height of the tree (worst case O(n))

Example:

final root = BinaryTreeNode<int>(10);
root.left = BinaryTreeNode<int>(5);
root.right = BinaryTreeNode<int>(15);
final inverted = invertTree(root);
// Now: root.left = 15, root.right = 5

Functions

invertTree<T>(BinaryTreeNode<T>? root) → BinaryTreeNode<T>?