2
2
from os import system
3
3
from Node import *
4
4
from time import sleep
5
+ import random
5
6
6
7
def display_menu (menu ):
7
8
"""
@@ -12,9 +13,15 @@ def display_menu(menu):
12
13
print (Fore .LIGHTBLUE_EX + " -> " + Fore .WHITE + " Binary Tree Options " + Fore .LIGHTBLUE_EX + " <-\n \n " )
13
14
14
15
try :
15
- print ("Current tree -> " , tree .data ,"\n \n " )
16
+ print ("Main tree -> " , tree .data ,"\n \n " )
16
17
except :
17
18
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
+
18
25
19
26
for k , function in menu .items ():
20
27
print (Fore .MAGENTA ,"|" ,k ,"| -> " , Fore .YELLOW ,function .__name__ )
@@ -25,22 +32,65 @@ def Binarytree():
25
32
print ("you have selected menu option BinaryTree making" ) # Simulate function output.
26
33
Nodes = []
27
34
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
28
72
while True :
29
73
n = int (input ("Enter the node : " ))
30
74
system ("clear" )
31
75
if (n != - 1 ) :
32
76
Nodes .append (n )
33
77
34
78
else :
35
- Tree = BinaryTree (Nodes )
36
- tree = Tree
79
+ Lary = BinaryTree (Nodes )
80
+ lary = Lary
37
81
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" )
38
89
39
- print (Tree .data )
40
90
input ("Press Enter to Continue\n " )
41
91
system ('clear' ) # clears stdout
42
92
43
-
93
+
44
94
def Draw ():
45
95
system ("clear" )
46
96
print ("you have selected menu option drawing" ) # Simulate function output.
@@ -117,7 +167,21 @@ def Search() :
117
167
input ("Press Enter to Continue\n " )
118
168
system ('clear' ) # clears stdout
119
169
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
+
121
185
def done ():
122
186
system ('clear' ) # clears stdout
123
187
print ("Goodbye" )
@@ -130,7 +194,7 @@ def get_word():
130
194
def main ():
131
195
# Create a menu dictionary where the key is an integer number and the
132
196
# 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 ]
134
198
menu_items = dict (enumerate (functions_names , start = 1 ))
135
199
136
200
while True :
@@ -144,4 +208,5 @@ def main():
144
208
if __name__ == "__main__" :
145
209
from colorama import *
146
210
print ("\n " ,Fore .WHITE , Back .RED ,"Please define the tree before using other options !!!" ,Back .RESET , "\n " )
211
+
147
212
main ()
0 commit comments