graphical for my binary tree

How it prints out so far:



























The code:

The spaces in prints will have to be adjusted for your command prompt / terminal

Making it print:

maple = BinaryTree(10.5)
maple.set(8, 'leftbranch')
maple.set(13, 'rightbranch')
maple.set(10, 'leftleaf')
maple.set(11, 'rightleaf')
maple.set(9, 'leftbranch')
maple.set(12, 'rightbranch')
graphic = PrintTree()

graphic.graphical(maple.root_node)

The class PrintTree:

class PrintTree(object):

def graphical(self, branches):
if branches != None:
righty = branches.right
lefty = branches.left
print("branch")
print(f" {branches} ")
print(f"                               {branches.key} ")
print("                     ///                  \\\\  ")
print("                   //                       \\   ")
print("                  /                          \\ ")
if righty and lefty:
print(f" \n                {lefty.key}     ______ ___>>>___ ______     {righty.key} \n")
elif righty and not lefty:
print(f" \n                None   ________ >>__________      {righty.key} \n ")
elif lefty and not righty:
print(f" \n                {lefty.key}     ______ ___>>>___ ______ None \n ")
else:
print(f"                   NONE _________________>>>___________________NONE")
if branches == None:
righty = None
lefty = None
if righty:
print("righty")
print(f"                               {righty.key} ")
print("                     ///                  \\\\  ")
print("                   //                       \\   ")
print("                  /                          \\ ")
left_child = righty.left
right_child = righty.right
if left_child or right_child:
print(f" \n {righty.left} ___>>>___{righty.right} \n")
if not left_child and not right_child:
print("              NONE  .........      .........  NONE   ")
if left_child:
self.graphical(left_child)
if right_child:
self.graphical(right_child)
if lefty:
print("lefty")
print(f"                                {lefty.key} ")
print("                  ///                    \\\\  ")
print("                 //                        \\   ")
print("                /                           \\ ")
left_child = lefty.left
right_child = lefty.right
if left_child or right_child:
print(f" \n {lefty.left}____>>>___ {lefty.right} \n ")
if not left_child and not right_child:
print("            NONE  .......__________.......   NONE")
if left_child:
self.graphical(left_child)
if right_child:
self.graphical(right_child)

if righty == None and lefty == None:
print(f"EMPTY Branch = {branches}")

Comments

Popular posts from this blog

playing with color in powershell python

JavaScript Ascii animation with while loops and console.log

playing with trigonometry sin in pygame