Download python/binary_search_tree.py from neopilot/PyRs2: direct link, hf CLI and curl.
- Browser
- Download file 594 Bytes
-
https://huggingface.co/datasets/neopilot/PyRs2/resolve/main/python/binary_search_tree.py
- Command line
-
hf download hf://datasets/neopilot/PyRs2/python/binary_search_tree.py
-
curl -L -o binary_search_tree.py https://huggingface.co/datasets/neopilot/PyRs2/resolve/main/python/binary_search_tree.py
594 Bytes
| class Node: | |
| def __init__(self, key): | |
| self.left = None | |
| self.right = None | |
| self.val = key | |
| def insert(root, key): | |
| if root is None: | |
| return Node(key) | |
| else: | |
| if root.val < key: | |
| root.right = insert(root.right, key) | |
| else: | |
| root.left = insert(root.left, key) | |
| return root | |
| def inorder(root): | |
| if root: | |
| inorder(root.left) | |
| print(root.val) | |
| inorder(root.right) | |
| r = Node(50) | |
| r = insert(r, 30) | |
| r = insert(r, 20) | |
| r = insert(r, 40) | |
| r = insert(r, 70) | |
| r = insert(r, 60) | |
| r = insert(r, 80) | |
| inorder(r) |