若執行下列 C 語言程式,所建立的二元樹為下列何者? #include<stdio.h> #include<stdlib.h> struct node { char data; struct node *left; struct node *right; }; void main(){ struct node *n1, *n2, *n3; n1 = (struct node *)malloc(sizeof(struct node)); n2 = (struct node *)malloc(sizeof(struct node)); n3 = (struct node *)malloc(sizeof(struct node)); n1->data = 'x'; n1->left = NULL; n1->right = NULL; n2->data = 'y'; n2->left = NULL; n2->right = NULL; n3->data = 'z'; n3->left = n1; n3->right = n2; }
Ay 為根,x 為左子節點,z 為右子節點
Bx 為根,z 為左子節點,y 為右子節點
Cz 為根,x 為左子節點,y 為右子節點正確答案
Dz 為根,y 為左子節點,x 為右子節點
答案與詳解
