-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree1.c
54 lines (46 loc) · 1.04 KB
/
tree1.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
54
#include<stdio.h>
#include<stdlib.h>
struct binaryTreeNode
{
int info;
struct binaryTreeNode *left,*right;
};
struct binaryTreeNode* createBinaryTree(struct binaryTreeNode *root)
{
int n;
static i;
root=(struct binaryTreeNode*)malloc(sizeof(struct binaryTreeNode));
if(root==NULL)
printf("sorry..node can't be created any more");
else
{
printf("Enter the info for %dst node : ",++i);
scanf("%d",root->info);
printf("Enter 0 for termination or leaf :");
scanf("%d",n);
if(!n)
root->left=root->right=NULL;
else
{
createBinaryTree(root->left);
createBinaryTree(root->right);
}
}
return root;
}
void perOrder(struct binaryTreeNode *root)
{
if(root!=NULL)
{
printf("%d\n",root->info);
preOrder(root->left);
preOrder(root->right);
}
}
int main()
{
struct binaryTreeNode *root;
root=createBinaryTree(root);
perOrder(root);
return 0;
}