Interested in advertising on Furbooru? Click here for information!
Furry Body Pillows - Preset and Custom Designs

Furbooru is not cheap to operate - help support us financially!

Description

class Node:
def \_\_init\_\_\(self, data\):

    self.left = None
    self.right = None
    self.data = data

def insert\(self, data\):
# Compare the new value with the parent node
if self.data:
if data < self.data:
if self.left is None:
self.left = Node(data)
else:
self.left.insert(data)
elif data > self.data:
if self.right is None:
self.right = Node(data)
else:
self.right.insert(data)
else:
self.data = data
# Print the tree
def PrintTree(self):
if self.left:
self.left.PrintTree()
print( self.data),
if self.right:
self.right.PrintTree()
# Use the insert method to add nodes
root = Node(12)
root.insert(6)
root.insert(14)
root.insert(3)
root.PrintTree()

safe182536 artist:cryptid-creations1500 fictional species170737 flora fauna258 hybrid9779 python100 reptile19863 snake4086 feral70970 ambiguous gender24977 plant9860 pun1193 solo237536 solo ambiguous11753 tree8098 tree python1

Comments

Syntax quick reference: **bold** *italic* ||hide text|| `code` __underline__ ~~strike~~ ^sup^ %sub%

Detailed syntax guide