Creating a BST with root value as val
(self, val)
| 23 | self.root = None |
| 24 | |
| 25 | def insert(self, val): |
| 26 | """Creating a BST with root value as val""" |
| 27 | # Check if tree has root with None value |
| 28 | if self.root is None: |
| 29 | self.root = Node(val) |
| 30 | # Here the tree already has one root |
| 31 | else: |
| 32 | current = self.root |
| 33 | while True: |
| 34 | if val < current.info: |
| 35 | if current.left: |
| 36 | current = current.left |
| 37 | else: |
| 38 | current.left = Node(val) |
| 39 | break |
| 40 | elif val > current.info: |
| 41 | if current.right: |
| 42 | current = current.right |
| 43 | else: |
| 44 | current.right = Node(val) |
| 45 | break |
| 46 | else: |
| 47 | break |
| 48 | |
| 49 | def search(self, val, to_delete=False): |
| 50 | current = self.root |
no test coverage detected