國立暨南國際大學 100 學年度第一學期小考試卷
(考試時間: 14:10-14:20)
科目名稱:資訊系統
與網路導論 |
開課系所:資訊工程
學系 |
任課教師
|
吳坤熹
|
系所別:
|
年級:
|
學號:
|
姓名:
|
考試日期
|
2011.12.28
|
-
(10%) Determine
whether the following code has syntax errors or not. If
it is correct, predict its output. If it is incorrect, point out
the mistake(s).
// Binary tree
#include <iostream>
using std::cout;
struct Node
{
char label;
Node* left;
Node* right;
};
void preorder(Node* p);
int main()
{
Node First = { 'A', NULL, NULL };
Node Second = { 'B', NULL, NULL };
Node Third = { 'C', NULL, NULL };
Node Fourth = { 'D', NULL, NULL };
Node Fifth = { 'E', &First, &Second };
Node Sixth = { 'F', &Third, &Fourth };
Node Seventh = { 'G', &Fifth, &Sixth };
preorder(&Seventh);
return 0;
}
void preorder(Node* p)
{
if (p)
{
cout << p->label;
preorder(p->left);
preorder(p->right);
}
}