-
Notifications
You must be signed in to change notification settings - Fork 0
/
main9.c
53 lines (45 loc) · 977 Bytes
/
main9.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Created by ge on 2023/12/12.
//
#include <stdio.h>
#include <stdlib.h>
typedef struct BTNode {
char data;
struct BTNode* lchild;
struct BTNode* rchild;
}BTNode, *Tree;
void create_biTree(Tree *T){
char ch;
scanf("%c", &ch);
if (ch == '#'){
*T = NULL;
}else {
*T = (BTNode *) malloc(sizeof(BTNode));
(*T)->data = ch;
printf("\n建立左子树\n");
(*T)->lchild = NULL;
(*T)->rchild = NULL;
create_biTree(&((*T)->lchild));
printf("\n建立右子树\n");
create_biTree(&((*T)->rchild));
}
return;
}
void destroy_tree(Tree *T){
if (*T) {
if ((*T)->lchild) {
destroy_tree(&((*T)->lchild));
}
if ((*T)->rchild) {
destroy_tree(&((*T)->rchild));
}
free(*T);
*T = NULL;
}
printf("\n销毁成功\n");
return;
}
int main () {
Tree tree;
create_biTree(&tree);
}