@@ -13,7 +13,10 @@ def display_menu(menu):
1313 print (Fore .LIGHTBLUE_EX + " -> " + Fore .WHITE + " Binary Tree Options " + Fore .LIGHTBLUE_EX + " <-\n \n " )
1414
1515 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 " )
1720 except :
1821 print ("Tree is not defined\n \n " )
1922
@@ -24,6 +27,8 @@ def display_menu(menu):
2427
2528
2629 for k , function in menu .items ():
30+ if k < 10 :
31+ k = "0" + str (k )
2732 print (Fore .MAGENTA ,"|" ,k ,"| -> " , Fore .YELLOW ,function .__name__ )
2833
2934
@@ -33,6 +38,7 @@ def Binarytree():
3338 Nodes = []
3439 global tree
3540 select = input ("Manually(1) or random(2) ? " )
41+
3642 if select == "1" :
3743 system ("clear" )
3844 while True :
@@ -82,7 +88,7 @@ def Comparing() :
8288 print (Lary .data )
8389 input ("Press Enter to compare\n " )
8490
85- if lary .PrintTree (str (1 )) == tree .PrintTree (str (1 )) :
91+ if lary .PrintTree (str (2 )) == tree .PrintTree (str (2 )) :
8692 print ("True" )
8793 else :
8894 print ("False" )
@@ -105,16 +111,25 @@ def Draw():
105111 system ('clear' ) # clears stdout
106112
107113
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 () :
109124 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.
111126
112- print (tree .MAX_MIN ())
127+ print (tree .MIN ())
113128
114129 input ("Press Enter to Continue\n " )
115130 system ('clear' ) # clears stdout
116131
117- def CountLeafs () :
132+ def count_leafs () :
118133 system ("clear" )
119134 print ("you have selected menu option count leafs" ) # Simulate function output.
120135
@@ -123,7 +138,7 @@ def CountLeafs() :
123138 input ("Press Enter to Continue\n " )
124139 system ('clear' ) # clears stdout
125140
126- def DeleteTree () :
141+ def delete_tree () :
127142 system ("clear" )
128143 print ("you have selected menu option delete tree" ) # Simulate function output.
129144
@@ -132,11 +147,11 @@ def DeleteTree() :
132147 input ("Press Enter to Continue\n " )
133148 system ('clear' ) # clears stdout
134149
135- def numberOfFloors () :
150+ def number_of_floors () :
136151 system ("clear" )
137152 print ("you have selected menu option number of floors" ) # Simulate function output.
138153
139- print (tree .floors_number ())
154+ print (tree .floors_number (tree . root ))
140155
141156 input ("Press Enter to Continue\n " )
142157 system ('clear' ) # clears stdout
@@ -167,14 +182,50 @@ def Search() :
167182 input ("Press Enter to Continue\n " )
168183 system ('clear' ) # clears stdout
169184
170- def CheckForFullTree () :
185+ def check_for_full_Tree () :
171186 system ("clear" )
172187 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 ())
174216
175217 input ("Press Enter to Continue\n " )
176218 system ('clear' ) # clears stdout
219+
220+ def Depth () :
221+ system ("clear" )
222+ print ("you have selected menu option depth " ) # Simulate function output.
177223
224+ print (tree .depth (tree .root ))
225+
226+ input ("Press Enter to Continue\n " )
227+ system ('clear' ) # clears stdout
228+
178229def Contributors () :
179230 system ("clear" )
180231 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():
194245def main ():
195246 # Create a menu dictionary where the key is an integer number and the
196247 # 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 ]
198249 menu_items = dict (enumerate (functions_names , start = 1 ))
199250
200251 while True :
0 commit comments