Skip to content

Instantly share code, notes, and snippets.

@hanjae-jea
Created June 6, 2019 01:58
Show Gist options
  • Save hanjae-jea/bc25777f34be4bd6a119065520fb0f96 to your computer and use it in GitHub Desktop.
Save hanjae-jea/bc25777f34be4bd6a119065520fb0f96 to your computer and use it in GitHub Desktop.
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
class Tree:
def __init__(self):
self.root = None
def insert(self, value):
if self.root is None:
self.root = Node(value)
return
# else
t = root
while True:
if t.value > value:
if t.right is None:
t.right = Node(value)
break
# else
t = t.right
else:
if t.left is None:
t.left = Node(value)
break
t = t.left
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment