-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathADT_Binary_Tree_create.c
53 lines (47 loc) · 1023 Bytes
/
ADT_Binary_Tree_create.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
/* The ADT Binary Tree
*/
// author: jaydattpatel
#include<stdio.h>
#include<stdlib.h>
struct node
{
char data;
struct node *left;
struct node *right;
};
typedef struct node *BTREE;
//typedef NODE ;
void inorder (BTREE root)
{
if (root != NULL)
{
inorder(root ->left);
printf("%c\t", root ->data);
inorder(root -> right);
}
}
BTREE init_node (char d1, BTREE p1, BTREE p2)
{
BTREE new_node;
new_node = (BTREE)(malloc(sizeof(struct node)));
new_node->data = d1;
new_node->left = p1;
new_node->right = p2;
return new_node;
}
BTREE create_tree(char data[], int i, int size)
{
if (i >= size)
return NULL;
else
return(init_node( data[i], create_tree(data, 2*i + 1, size), create_tree(data, 2*i + 2, size) ));
}
int main()
{
char data[] = {'A', 'B', 'C', 'D', 'E'};
BTREE b;
b = create_tree(data, 0, 5);
inorder(b);
printf("\n\n");
return 0;
}