Skip to content

Instantly share code, notes, and snippets.

@nooperpudd
Created August 24, 2018 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nooperpudd/1cb53d61ba8d805bea4903b9156956de to your computer and use it in GitHub Desktop.
Save nooperpudd/1cb53d61ba8d805bea4903b9156956de to your computer and use it in GitHub Desktop.
ss
class Node:
def __init__(self, info):
self.info = info
self.left = None
self.right = None
self.level = None
def __str__(self):
return str(self.info)
class BinarySearchTree:
def __init__(self):
self.root = None
def create(self, val):
if self.root == None:
self.root = Node(val)
else:
current = self.root
while True:
if val < current.info:
if current.left:
current = current.left
else:
current.left = Node(val)
break
elif val > current.info:
if current.right:
current = current.right
else:
current.right = Node(val)
break
else:
break
tree = BinarySearchTree()
t=7
arr=[3 ,5, 2, 1, 4, 6, 7]
for i in range(t):
tree.create(arr[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment