-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhello.py
More file actions
40 lines (35 loc) · 766 Bytes
/
Copy pathhello.py
File metadata and controls
40 lines (35 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Node:
def __init__(self,data):
self.left = None
self.right = None
self.data = data
def insert(self,data):
if self.data:
if data < self.data:
if self.left is None:
self.left=Node(data)
else:
self.left.insert(data)
if data > self.data:
if self.right is None:
self.right=Node(data)
else:
self.right.insert(data)
else:
self.data=data
def findval(self,lkpval):
if lkpval < self.data:
if self.left is None:
return str(lkpval) + " Not found"
return
elif lkpval > self.data:
if self.right is None:
return str(lkpval) + " Not found"
else:
print(str(lkpval) + " Found")
def PrintTree(self):
print(self.data)
root = Node(10)
root.insert(1)
root.insert(11)
print(root.findval(1))