Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 6f011ff

Browse files
committed
Made more options
1 parent bfa7e38 commit 6f011ff

File tree

8 files changed

+93
-13
lines changed

8 files changed

+93
-13
lines changed

Node.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ def search(self, node: Node , Arg: int) :
229229
elif node.value < Arg:
230230
return self.search(node.right, Arg)
231231

232-
233-
B = BinaryTree([10,1,12])
234-
print(B.search(B.root,15))
232+
233+
def FullTree(node: Node) :
234+
queue = []
235+
queue.append(node)
236+
237+
while queue != []:
238+
temp = queue.pop()
239+
240+
if temp.left == None and temp.right == None:
241+
continue
242+
elif temp.right != None and temp.left != None:
243+
queue.append(temp.right)
244+
queue.append(temp.left)
245+
else:
246+
return False
247+
return True
248+
249+

__pycache__/Node.cpython-310.pyc

289 Bytes
Binary file not shown.

__pycache__/Node.cpython-311.pyc

10.6 KB
Binary file not shown.

__pycache__/Node.cpython-39.pyc

554 Bytes
Binary file not shown.

__pycache__/graphical.cpython-311.pyc

4.02 KB
Binary file not shown.

__pycache__/graphical.cpython-39.pyc

0 Bytes
Binary file not shown.

graphical.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def draw(node, x, y, dx):
5656
t.hideturtle()
5757
turtle.mainloop()
5858

59-
if __name__ == '__main__':
60-
Banching([2,3,1,4,5])
61-
drawtree()
59+
# if __name__ == '__main__':
60+
# Banching([2,3,1,4,5])
61+
# drawtree()
6262

6363

6464

main.py

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from os import system
33
from Node import *
44
from time import sleep
5+
import random
56

67
def 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+
4494
def 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,"\nAmirhossein Sabry 40011573\nKimia Keivanloo 40015753\n\nWWW.GEEKFORGEEKS.COM \u2764\uFE0F")
181+
sleep(5)
182+
input("Press Enter to Continue\n")
183+
system('clear') # clears stdout
184+
121185
def done():
122186
system('clear') # clears stdout
123187
print("Goodbye")
@@ -130,7 +194,7 @@ def get_word():
130194
def 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():
144208
if __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

Comments
 (0)