-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtreemirrorswap.c
More file actions
35 lines (28 loc) · 905 Bytes
/
btreemirrorswap.c
File metadata and controls
35 lines (28 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* Copyright © 2021-2023 Chee Bin HOH. All rights reserved.
*
* Given the root node of a binary tree, swap the ‘left’ and ‘right’ children
* for each node.
*/
#include "btree.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
struct TreeNode *root = NULL;
root = addTreeNode(root, 5);
root = addTreeNode(root, 3);
root = addTreeNode(root, 7);
root = addTreeNode(root, 4);
printf("The tree topology:\n");
printf("\n");
printTreeNodeInTreeTopology(root);
printf("\n"); // we can introduce wrapper entry call to printTreeNodeInOrder
// to printf \n
printf("\n");
treeMirrorSwap(root);
printf("The tree topology after mirror swap of tree node:\n");
printf("\n");
printTreeNodeInTreeTopology(root);
printf("\n"); // we can introduce wrapper entry call to printTreeNodeInOrder
// to printf \n
printf("\n");
return 0;
}