-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarytreearray.c
More file actions
39 lines (33 loc) · 908 Bytes
/
binarytreearray.c
File metadata and controls
39 lines (33 loc) · 908 Bytes
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
#include<stdio.h>
#include<math.h>
int main()
{
int i,size,n,nodes;
char myarray[50];
printf("Enter the total height of the binary tree:");
scanf("%d",&n);
size=n+1;
printf("Enter the Root Element:");
scanf(" %c",&myarray[0]);
nodes=(n*n)-2;
printf("\nEnter ""_"" to represent Free space\n");
for(i=0;i<nodes+1;i++){
if(myarray[i]!='_'){
printf("Enter the Left child of %c :",myarray[i]);
scanf(" %c",&myarray[(2*i)+1]);
printf("Enter the Right child of %c :",myarray[i]);
scanf(" %c",&myarray[(2*i)+2]);
}
else{
myarray[(2*i)+1]='_';
myarray[(2*i)+2]='_';
}
}
printf("The binary tree using array representation=\n");
nodes=(size*size)-1;
for(i=0;i<nodes;i++){
printf(" %c\t",myarray[i]);
}
printf("\n");
return 0;
}