22from os import system
33from Node import *
44from time import sleep
5+ import random
56
67def display_menu (menu ):
78 """
@@ -12,9 +13,15 @@ def display_menu(menu):
1213 print (Fore .LIGHTBLUE_EX + " -> " + Fore .WHITE + " Binary Tree Options " + Fore .LIGHTBLUE_EX + " <-\n \n " )
1314
1415 try :
15- print ("Current tree -> " , tree .data ,"\n \n " )
16+ print ("Main tree -> " , tree .data ,"\n \n " )
1617 except :
1718 print ("Tree is not defined\n \n " )
19+
20+ try :
21+ print ("Second tree -> " , lary .data ,"\n \n " )
22+ except :
23+ print ("Second tree is not defined\n \n " )
24+
1825
1926 for k , function in menu .items ():
2027 print (Fore .MAGENTA ,"|" ,k ,"| -> " , Fore .YELLOW ,function .__name__ )
@@ -25,22 +32,65 @@ def Binarytree():
2532 print ("you have selected menu option BinaryTree making" ) # Simulate function output.
2633 Nodes = []
2734 global tree
35+ select = input ("Manually(1) or random(2) ? " )
36+ if select == "1" :
37+ system ("clear" )
38+ while True :
39+ n = int (input ("Enter the node : " ))
40+ system ("clear" )
41+ if (n != - 1 ) :
42+ Nodes .append (n )
43+
44+ else :
45+ Tree = BinaryTree (Nodes )
46+ tree = Tree
47+ break
48+
49+ elif select == "2" :
50+ system ("clear" )
51+ rang = int (input ("How many nodes do you want to be generated ? " ))
52+
53+ for i in range (rang ):
54+ r = random .randint (0 ,100 )
55+ if r in Nodes :
56+ continue
57+ else :
58+ Nodes .append (r )
59+ Tree = BinaryTree (Nodes )
60+ tree = Tree
61+
62+
63+ print (Tree .data )
64+ input ("Press Enter to Continue\n " )
65+ system ('clear' ) # clears stdout
66+
67+ def Comparing () :
68+ system ("clear" )
69+ print ("you have selected menu option Comparing" ) # Simulate function output.
70+ Nodes = []
71+ global lary
2872 while True :
2973 n = int (input ("Enter the node : " ))
3074 system ("clear" )
3175 if (n != - 1 ) :
3276 Nodes .append (n )
3377
3478 else :
35- Tree = BinaryTree (Nodes )
36- tree = Tree
79+ Lary = BinaryTree (Nodes )
80+ lary = Lary
3781 break
82+ print (Lary .data )
83+ input ("Press Enter to compare\n " )
84+
85+ if lary .PrintTree (str (1 )) == tree .PrintTree (str (1 )) :
86+ print ("True" )
87+ else :
88+ print ("False" )
3889
39- print (Tree .data )
4090 input ("Press Enter to Continue\n " )
4191 system ('clear' ) # clears stdout
4292
43-
93+
4494def Draw ():
4595 system ("clear" )
4696 print ("you have selected menu option drawing" ) # Simulate function output.
@@ -117,7 +167,21 @@ def Search() :
117167 input ("Press Enter to Continue\n " )
118168 system ('clear' ) # clears stdout
119169
120-
170+ def CheckForFullTree () :
171+ system ("clear" )
172+ print ("you have selected menu option Checking for full tree " ) # Simulate function output.
173+ print (tree .FullTree ())
174+
175+ input ("Press Enter to Continue\n " )
176+ system ('clear' ) # clears stdout
177+
178+ def Contributors () :
179+ system ("clear" )
180+ print (Fore .RESET ,"\n Amirhossein Sabry 40011573\n Kimia Keivanloo 40015753\n \n WWW.GEEKFORGEEKS.COM \u2764 \uFE0F " )
181+ sleep (5 )
182+ input ("Press Enter to Continue\n " )
183+ system ('clear' ) # clears stdout
184+
121185def done ():
122186 system ('clear' ) # clears stdout
123187 print ("Goodbye" )
@@ -130,7 +194,7 @@ def get_word():
130194def main ():
131195 # Create a menu dictionary where the key is an integer number and the
132196 # value is a function name.
133- functions_names = [Binarytree , Draw , MAX_and_MIN , CountLeafs , DeleteTree , numberOfFloors ,traversal , Search , done ]
197+ functions_names = [Binarytree ,Comparing , Draw , MAX_and_MIN , CountLeafs , DeleteTree , numberOfFloors ,traversal , Search ,CheckForFullTree , Contributors , done ]
134198 menu_items = dict (enumerate (functions_names , start = 1 ))
135199
136200 while True :
@@ -144,4 +208,5 @@ def main():
144208if __name__ == "__main__" :
145209 from colorama import *
146210 print ("\n " ,Fore .WHITE , Back .RED ,"Please define the tree before using other options !!!" ,Back .RESET , "\n " )
211+
147212 main ()
0 commit comments