Generate a Mirror Image of a tree. Change a tree so that the roles of the left and right pointers are swapped at every node

Generate a Mirror Image of a tree. Change a tree so that the roles of the left and right pointers are swapped at every node
void mirror(struct node* node) {
if (node==NULL) {
return;
}
else {
struct node* temp; // do the subtrees
mirror(node->left); mirror(node->right); // swap the pointers in this node
temp = node->left;
node->left = node->right;
node->right = temp;
}
}

No comments: