So the tree:
1: 10 2: / \ 3: 7 25 4: / \ 5: 2 8 1: 10 2: / \ 3: 25 7 4: / \ 5: 8 21: void mirror(struct node* head) {
2: if (head == 0)
3: return;
4: node* temp = head->left; 5: head->left = head->right;6: head->right = temp; // switch left child with right child
7: mirror(head->left); // then repeat the process with each child
8: mirror(head->right); 9: }
No comments:
Post a Comment