Complete the code to print the root node's value in preorder traversal.
void preorder(struct Node* root) {
if (root == NULL) return;
printf("%d ", root->[1]);
}The preorder traversal visits the root node first, so we print root->data.
Complete the code to recursively traverse the left subtree in preorder.
void preorder(struct Node* root) {
if (root == NULL) return;
printf("%d ", root->data);
preorder(root->[1]);
}In preorder traversal, after visiting the root, we visit the left subtree first using root->left.
Fix the error in the code to correctly traverse the right subtree in preorder.
void preorder(struct Node* root) {
if (root == NULL) return;
printf("%d ", root->data);
preorder(root->left);
preorder(root->[1]);
}After traversing the left subtree, preorder traversal visits the right subtree using root->right.
Fill both blanks to complete the preorder traversal function visiting root, left, then right.
void preorder(struct Node* root) {
if (root == NULL) return;
printf("%d ", root->[1]);
preorder(root->[2]);
preorder(root->right);
}First print root->data, then recursively traverse the left subtree with root->left, and finally the right subtree.
Fill all three blanks to implement preorder traversal visiting root, left, then right.
void preorder(struct Node* root) {
if (root == NULL) return;
printf("%d ", root->[1]);
preorder(root->[2]);
preorder(root->[3]);
}Preorder traversal visits the root node's data, then recursively visits the left subtree, then the right subtree.
