Tree Tarversal Code
Tree Tarversal Code
if (value == -1)
return NULL;
return newNode;
}
int main() {
printf("Build the binary tree:\n");
struct Node* root = buildTree();
printf("Binary tree created successfully.\n");
return 0;
}
Preorder traversal (Root, Left, Right)
void preorderTraversal(struct Node* root) {
if (root == NULL)
return;
printf("%d ", root->data);
preorderTraversal(root->left);
preorderTraversal(root->right);
}