#include <stdio.h>
#include <stdlib.h>
// Define the structure of a tree node
struct Node {
int data;
struct Node* left;
struct Node* right;
};
// Function to create a new node
struct Node* createNode(int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}
// Function to calculate the size of the tree
int calculateSize(struct Node* root) {
if (root == NULL)
return 0; // Base case: an empty tree has size 0
return calculateSize(root->left) + calculateSize(root->right) + 1;
}
int main() {
// Creating the tree shown in your image
struct Node* root = createNode(5);
root->left = createNode(1);
root->right = createNode(6);
root->left->left = createNode(3);
root->right->left = createNode(7);
root->right->right = createNode(4);
// Calculate the size of the tree
int size = calculateSize(root);
// Output the size
printf("The size of the tree is: %d\n", size);
return 0;
}