Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DrzewoBST:
- def __init__(self, value = None):
- self.val = value
- self.left = None
- self.right = None
- def __str__(self):
- return "[%s, %s, %s]" % (self.left, str(self.val), self.right)
- def wstawianie(self, wartosc):
- if self is None:
- self = DrzewoBST(wartosc)
- if wartosc < self.val:
- if self.left is None:
- self.left = DrzewoBST(wartosc)
- else:
- self.left.wstawianie(wartosc)
- elif wartosc > self.val:
- if self.right is None:
- self.right = DrzewoBST(wartosc)
- else:
- self.right.wstawianie(wartosc)
- def wyszukiwanie(self, liczba):
- print(self.val)
- if self is None:
- return False
- if int(self.val) == liczba:
- return True
- if liczba < self.val:
- self.left.wyszukiwanie(liczba)
- else:
- self.right.wyszukiwanie(liczba)
- t = DrzewoBST(2)
- t.wstawianie(3)
- t.wstawianie(3)
- print(t.wyszukiwanie(3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement