-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarytree.c
More file actions
61 lines (40 loc) · 760 Bytes
/
Copy pathbinarytree.c
File metadata and controls
61 lines (40 loc) · 760 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<stdio.h>
void main()
{
int pos ,limit,i;
char choice='y';
printf("enter the no of nodes:");
scanf("%d",&limit);
int t[limit+1];
printf("enter the data in the node :");
for(i=1;i<=limit;i++){
scanf("%d",&t[i]);
}
while(choice=='y')
{
printf("enter the position you want to check:");
scanf("%d",&pos);
if(pos/2==0){
printf("no parent node\n");
}
else{
printf("parent node is %d\n",t[pos/2]);
}
if((2*pos)>limit){
printf("no left child node\n");
}
else{
printf("left child node is %d\n",t[2*pos]);
}
if(((2*pos)+1)>limit){
printf("no right child node\n");
}
else{
printf("right child node is %d\n",t[2*pos+1]);
}
printf("Do you want to continue the program:");
scanf(" %c",&choice);
if(choice!='y'){
break;
}
}}