(10%)
Determine
whether the syntax of the following code is correct or not. If it
is
correct, predict its output. If it is incorrect, point out the
mistake(s).
/* Binary Tree */
#include <iostream>
struct Node {
char c;
Node* left;
Node* right;
};
void printTree(Node* p) {
if (p) {
printTree(p->left);
printTree(p->right);
std::cout << p->c;
}
}
int main() {
Node n1 = { 'A', nullptr, nullptr };
Node n2 = { 'I', nullptr, nullptr };
Node n3 = { 'W', nullptr, nullptr };
Node n4 = { 'O', nullptr, nullptr };
Node n5 = { 'R', &n1, &n2 };
Node n6 = { 'L', &n3, &n4 };
Node n7 = { 'F', &n5, &n6 };
printTree(&n7);
return 0;
}