文章
126
粉丝
35
获赞
0
访问
24.6k
(1)递归,层序遍历
(2)
BTree *createBinaryTree(char a[][10], int n) {
if (strcmp(a[0], "null") == 0) {
return NULL;
}
int i = 0;
BTree *root = (struct node*)malloc(sizeof(struct node));
strcpy(root->data, a[i++]);
root->left = NULL;
root->right = NULL;
struct node** que = (struct node**)malloc(sizeof(struct node*));
int front = 0, rear = 0;
BTree *curr = root;
que[rear++] = curr;
while (front < rear && i < n) {
curr = que[front++];
for (int j = 0; j < 2 && i < n; j++, i++) {
if (strcmp(a[i], "null") != 0) {
if (j == 0) {
 ...
登录后发布评论
暂无评论,来抢沙发