14. Tree/invert_binary_tree.cpp
void invertBinaryTree(Node* root)
{
    // base case: if the tree is empty
    if (root == nullptr) {
        return;
    }
 
    // swap left subtree with right subtree
    swap(root->left, root->right);
 
    // invert left subtree
    invertBinaryTree(root->left);
 
    // invert right subtree
    invertBinaryTree(root->right);
}
// Function to invert a given binary tree using preorder traversal
Function to invert a given binary tree using preorder traversal
Function to invert a given binary tree using preorder traversal
void invertBinaryTree(Node* root)
{
    if (root == nullptr) {
        return;
    }
    swap(root->left, root->right);
    invertBinaryTree(root->left);
    invertBinaryTree(root->right);
}
void invertBinaryTree ( Node * root ) { if ( root == nullptr ) { return ; } swap ( root -> left , root -> right ) ; invertBinaryTree ( root -> left ) ; invertBinaryTree ( root -> right ) ; }
Function to invert a given binary tree using preorder traversal
Function to invert a given binary tree using preorder traversal
// base case: if the tree is empty // swap left subtree with right subtree // invert left subtree // invert right subtree