invertTree<T> function
Implementation
BinaryTreeNode<T>? invertTree<T>(BinaryTreeNode<T>? root) {
if (root == null) return null;
// Swap left and right children
final BinaryTreeNode<T>? temp = root.left;
root.left = root.right;
root.right = temp;
// Recursively invert subtrees
invertTree(root.left);
invertTree(root.right);
return root;
}