#include <iostream>
struct Node {
int data;
Node* left;
Node* right;
Node(int val) : data(val), left(nullptr), right(nullptr) {}
};
// Function to perform an in-order traversal of the binary tree
void inOrderTraversal(Node* root) {
if (root == nullptr) {
return; // Base case: if the node is null, return
}
inOrderTraversal(root->left); // Traverse the left subtree
std::cout << root->data << " "; // Visit the root
inOrderTraversal(root->right); // Traverse the right subtree
}
int main() {
// Create a simple binary tree
Node* root = new Node(1);
root->left = new Node(2);
root->right = new Node(3);
root->left->left = new Node(4);
root->left->right = new Node(5);
std::cout << "In-order traversal: ";
inOrderTraversal(root);
std::cout << std::endl;
// Free the allocated memory (not shown for simplicity)
return 0;
}