@@ -13,7 +13,10 @@ def display_menu(menu):
13
13
print (Fore .LIGHTBLUE_EX + " -> " + Fore .WHITE + " Binary Tree Options " + Fore .LIGHTBLUE_EX + " <-\n \n " )
14
14
15
15
try :
16
- print ("Main tree -> " , tree .data ,"\n \n " )
16
+ if tree .root == None :
17
+ print ("tree is not defind\n \n " )
18
+ else :
19
+ print ("Main tree -> " , tree .data , "\n \n " )
17
20
except :
18
21
print ("Tree is not defined\n \n " )
19
22
@@ -24,6 +27,8 @@ def display_menu(menu):
24
27
25
28
26
29
for k , function in menu .items ():
30
+ if k < 10 :
31
+ k = "0" + str (k )
27
32
print (Fore .MAGENTA ,"|" ,k ,"| -> " , Fore .YELLOW ,function .__name__ )
28
33
29
34
@@ -33,6 +38,7 @@ def Binarytree():
33
38
Nodes = []
34
39
global tree
35
40
select = input ("Manually(1) or random(2) ? " )
41
+
36
42
if select == "1" :
37
43
system ("clear" )
38
44
while True :
@@ -82,7 +88,7 @@ def Comparing() :
82
88
print (Lary .data )
83
89
input ("Press Enter to compare\n " )
84
90
85
- if lary .PrintTree (str (1 )) == tree .PrintTree (str (1 )) :
91
+ if lary .PrintTree (str (2 )) == tree .PrintTree (str (2 )) :
86
92
print ("True" )
87
93
else :
88
94
print ("False" )
@@ -105,16 +111,25 @@ def Draw():
105
111
system ('clear' ) # clears stdout
106
112
107
113
108
- def MAX_and_MIN ():
114
+ def max ():
115
+ system ("clear" )
116
+ print ("you have selected menu option max " ) # Simulate function output.
117
+
118
+ print (tree .MAX ())
119
+
120
+ input ("Press Enter to Continue\n " )
121
+ system ('clear' ) # clears stdout
122
+
123
+ def min () :
109
124
system ("clear" )
110
- print ("you have selected menu option max and min" ) # Simulate function output.
125
+ print ("you have selected menu option min" ) # Simulate function output.
111
126
112
- print (tree .MAX_MIN ())
127
+ print (tree .MIN ())
113
128
114
129
input ("Press Enter to Continue\n " )
115
130
system ('clear' ) # clears stdout
116
131
117
- def CountLeafs () :
132
+ def count_leafs () :
118
133
system ("clear" )
119
134
print ("you have selected menu option count leafs" ) # Simulate function output.
120
135
@@ -123,7 +138,7 @@ def CountLeafs() :
123
138
input ("Press Enter to Continue\n " )
124
139
system ('clear' ) # clears stdout
125
140
126
- def DeleteTree () :
141
+ def delete_tree () :
127
142
system ("clear" )
128
143
print ("you have selected menu option delete tree" ) # Simulate function output.
129
144
@@ -132,11 +147,11 @@ def DeleteTree() :
132
147
input ("Press Enter to Continue\n " )
133
148
system ('clear' ) # clears stdout
134
149
135
- def numberOfFloors () :
150
+ def number_of_floors () :
136
151
system ("clear" )
137
152
print ("you have selected menu option number of floors" ) # Simulate function output.
138
153
139
- print (tree .floors_number ())
154
+ print (tree .floors_number (tree . root ))
140
155
141
156
input ("Press Enter to Continue\n " )
142
157
system ('clear' ) # clears stdout
@@ -167,14 +182,50 @@ def Search() :
167
182
input ("Press Enter to Continue\n " )
168
183
system ('clear' ) # clears stdout
169
184
170
- def CheckForFullTree () :
185
+ def check_for_full_Tree () :
171
186
system ("clear" )
172
187
print ("you have selected menu option Checking for full tree " ) # Simulate function output.
173
- print (tree .FullTree ())
188
+ print (tree .FullTree (tree .root ))
189
+
190
+ input ("Press Enter to Continue\n " )
191
+ system ('clear' ) # clears stdout
192
+
193
+ def is_Complete () :
194
+ system ("clear" )
195
+ print ("you have selected menu option is complete tree " ) # Simulate function output.
196
+
197
+ print (tree .isComplete ())
198
+
199
+ input ("Press Enter to Continue\n " )
200
+ system ('clear' ) # clears stdout
201
+
202
+ def get_count_of_children () :
203
+ system ("clear" )
204
+ print ("you have selected menu option is count of children " ) # Simulate function output.
205
+
206
+ print (tree .get_count_of_children ())
207
+
208
+ input ("Press Enter to Continue\n " )
209
+ system ('clear' ) # clears stdout
210
+
211
+ def number_of_nodes () :
212
+ system ("clear" )
213
+ print ("you have selected menu option is count of children " ) # Simulate function output.
214
+
215
+ print (tree .number_of_nodes ())
174
216
175
217
input ("Press Enter to Continue\n " )
176
218
system ('clear' ) # clears stdout
219
+
220
+ def Depth () :
221
+ system ("clear" )
222
+ print ("you have selected menu option depth " ) # Simulate function output.
177
223
224
+ print (tree .depth (tree .root ))
225
+
226
+ input ("Press Enter to Continue\n " )
227
+ system ('clear' ) # clears stdout
228
+
178
229
def Contributors () :
179
230
system ("clear" )
180
231
print (Fore .RESET ,"\n Amirhossein Sabry 40011573\n Kimia Keivanloo 40015753\n \n WWW.GEEKFORGEEKS.COM \u2764 \uFE0F " )
@@ -194,7 +245,7 @@ def get_word():
194
245
def main ():
195
246
# Create a menu dictionary where the key is an integer number and the
196
247
# value is a function name.
197
- functions_names = [Binarytree , Comparing , Draw , MAX_and_MIN , CountLeafs , DeleteTree , numberOfFloors , traversal , Search ,CheckForFullTree , Contributors ,done ]
248
+ functions_names = [Binarytree , Comparing , Draw , max , min , count_leafs , delete_tree , number_of_floors , Depth , traversal , Search , check_for_full_Tree , is_Complete , get_count_of_children , number_of_nodes , Contributors , done ]
198
249
menu_items = dict (enumerate (functions_names , start = 1 ))
199
250
200
251
while True :
0 commit comments