Function to perform preorder traversal on a given binary tree
| 28 | |
| 29 | // Function to perform preorder traversal on a given binary tree |
| 30 | void preorder(Node* root) |
| 31 | { |
| 32 | if (root == nullptr) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | cout << root->data << " "; |
| 37 | preorder(root->left); |
| 38 | preorder(root->right); |
| 39 | } |
| 40 | |
| 41 | // Function to invert a given binary tree using preorder traversal |
| 42 | void swap(TreeNode* root) |