-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCBST_Printing_Functions.cpp
162 lines (138 loc) · 5.4 KB
/
CBST_Printing_Functions.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "CBST_Tree_Company.h"
//print functions
bool CBST::print_CL(int head, Info_collection *info)
{//print_CL
if(!checkexitence(head)){info->Kind = -1; return false;}
int key = get_TheKey(head); info->Kind = 0;
int item = get_info(head, Cousin);
if(item > 0){
cout<<"(";
while(item > 0){//print loop
if(get_TheKey(item) != key){info->Kind = item; return false;}
cout<<item; item = get_info(item, Cousin);if(item > 0) cout<<"; "; else break;
}//loop
cout<<")";
}
return true;
}//print_CL
bool CBST::print_ARA(int head, Info_collection *info)
{//print_ARA
bool flag = true;
if(!checkexitence(head)){info->Kind = -1; return false;}
int Item = head;
while(Item > 0){
int next = get_info(Item, Successor);
if(next > 0 ){
if(!checkexitence(head)){info->Kind = -2; return false;}
else if(get_TheKey(Item) >= get_TheKey(next)){info->Kind = -3; return false;}
}
cout<<Item;
if(get_info(Item, Cousin)){//print CL
flag = print_CL(Item, info);
if(!flag){cout<<"\n print CL, position =>"<<info->Kind; return false;}
}
cout<<"; "; Item = next;
}
return flag;
}//print_ARA
void CBST::printOverallInfo()
{
cout<<endl;
cout<<"1. min = "<<the_overallinfo[Min_Extremum]<<endl;
cout<<"2. max = "<<the_overallinfo[Max_Extremum]<<endl;
cout<<"3. root = "<<the_overallinfo[Root]<<endl;
cout<<"4. num_agencies = "<<the_overallinfo[num_Agencies]<<endl;
cout<<"5. num_items = "<<the_overallinfo[num_Items]<<endl;
}
bool CBST::printTree(int *aid_1, int *aid_2, Info_collection *info)
{
printOverallInfo(); cout<<endl;
if(the_overallinfo[Root] > 0)
{
if(!checkexitence(the_overallinfo[Root])){info->Kind = -1; return false;}//check root
int index = 1; aid_1[0] = index; aid_1[index] = the_overallinfo[Root];
while(index){//loop
index = 0;
for(int n = 1; n <= aid_1[0]; n++){
int father = aid_1[n]; if(!checkexitence(father)){info->Kind = father; return false;}
int left = get_info(father, Left_child); int right = get_info(father, Right_child);
if(left > 0){
index ++; aid_2[index] = left; aid_2[0] = index; cout<<left<<"<-- ";
}
cout<<father;
/**/
if(get_info(father, Cousin) > 0){
if(!print_CL(father, info)) {info->Kind = father; return false;}
}
if(right > 0){
index ++; aid_2[index] = right; aid_2[0] = index; cout<<" -->"<<right;
}
cout<<"; ";
}cout<<endl;
int *p = aid_1; aid_1 = aid_2; aid_2 = p; aid_2[0] = 0;
}//loop
}
else{
cout<<"\n empty tree"<<endl;
}
return true;
}
bool CBST::PrintItem(int item)
{
if(!checkexitence(item)) return false;
cout<<endl;
cout<<"1. Parent = "<<get_info(item, Parent)<<endl;
cout<<"2. Left_Child = "<<get_info(item, Left_child)<<endl;
cout<<"3. Right_Child = "<<get_info(item, Right_child)<<endl;
cout<<"4. Couisin = "<<get_info(item, Cousin)<<endl;
cout<<"5. InOrOut = "<<get_info(item, InOrOut)<<endl;
cout<<"6. Successor = "<<get_info(item, Successor)<<endl;
cout<<"7. Predecessor = "<<get_info(item, Predecessor)<<endl;
return true;
}
//flexion model
bool CBST::Flexion_printTree(int *aid_1, int *aid_2, Info_collection *info)
{//Flexion_printTree
printOverallInfo(); cout<<endl;
if(the_overallinfo[Root] > 0)
{
if(!checkexitence(the_overallinfo[Root])){info->Kind = -1; return false;}//check root
int index = 1; aid_1[0] = index; aid_1[index] = the_overallinfo[Root];
while(index){//loop
index = 0;
for(int n = 1; n <= aid_1[0]; n++){
int father = aid_1[n]; if(!checkexitence(father)){info->Kind = father; return false;}
int left = get_info(father, Left_child); int right = get_info(father, Right_child);
if(left > 0){
index ++; aid_2[index] = left; aid_2[0] = index; cout<<left<<"<-- ";
}
cout<<father<<"("<<get_info(father, Flexion)<<", "<<get_info(father, Self_counter)<<")";
if(right > 0){
index ++; aid_2[index] = right; aid_2[0] = index; cout<<" -->"<<right;
}
cout<<"; ";
}cout<<endl;
int *p = aid_1; aid_1 = aid_2; aid_2 = p; aid_2[0] = 0;
}//loop
}
else{
cout<<"\n empty tree"<<endl;
}
return true;
}//Flexion_printTree
bool CBST::Flexion_print_ARA(int head, Info_collection *info)
{//print_ARA
bool flag = true;
if(!checkexitence(head)){info->Kind = -1; return false;}
int Item = head;
while(Item > 0){
int next = get_info(Item, Successor);
if(next > 0 ){
if(!checkexitence(Item)){info->Kind = -2; return false;}
else if(get_TheKey(Item) >= get_TheKey(next)){info->Kind = -3; return false;}
}
cout<<Item<<"("<<get_info(Item, Flexion)<<", "<<get_info(Item, Self_counter)<<"); ";
Item = next;
}
return flag;
}//print_ARA