-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadedBINARYTREE.c
More file actions
67 lines (65 loc) · 902 Bytes
/
threadedBINARYTREE.c
File metadata and controls
67 lines (65 loc) · 902 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
62
63
64
65
66
67
NODEPTR maketree(int x)
{
NODEPTR p;
p=getnode();
p->info=x;
p->left=NULL;
p->right=NULL;
p->rthread=TRUE;
return(p);
}
void setleft(NODEPTR p,int x)
{
NODEPTR q;
if(p==NULL)
error("void insertion");
else if(p->left!=NULL)
error("invalid insertion");
else{
q=getnode();
q->info=x;
p->left=q;
q->left=NULL;
q->right=p;
q->rthread=TRUE;
}
}
void setright(NODEPTR p,int x)
{
NODEPTR q,r;
if(p==NULL)
error("void insertion");
else if(!p->rthread)
error("invalid insertion");
else{
q=getnode();
q->info=x;
r=p->right;
p->right=q;
p->rthread=FALSE;
q->left=NULL;
q->right=r;
q->rthread=TRUE;
}
}
void intrav4(int tree)
{
int p,q;
p=tree;
do{
q=0;
while(p!=0){
q=p;
p=node[p].left;
}
if(q!=0){
printf("%d\n",node[q].info);
p=mode[q].right;
while(p<0){
q=-p;
printf("%d\n",node[q].info);
p=node[q].right;
}
}
}while(q!=0);
}