-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path22.c
68 lines (55 loc) · 833 Bytes
/
22.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//binary tree using array
#include<stdio.h>
#define n 30
int a[n],c;
void buildtree(int i,int item)
{
char y;
if(i!=0)
{
int p=item;
a[i]=item;
printf("Node %d has left child (y/n): ",p);
scanf(" %c",&y);
if(y=='y' || y=='Y')
{
c++;
printf("Enter : ");
scanf("%d",&item);
buildtree(2*i,item);
}
else
{
c++;
buildtree(0,0);
}
printf("Node %d has right child (y/n): ",p);
scanf(" %c",&y);
if(y=='y' || y=='Y')
{
c++;
printf("Enter : ");
scanf("%d",&item);
buildtree(2*i+1,item);
}
else
{
c++;
buildtree(0,0);
}
}
}
void main()
{
int j,root;
printf("Enter the root node : ");
scanf("%d",&root);
c++;
buildtree(1,root);
printf("The tree is : ");
for(j=1;j<=c;j++)
{
printf("%d ",a[j]);
}
printf("\n");
}