Back to Freecodecamp

Step 15

curriculum/challenges/english/blocks/learn-tree-traversal-by-building-a-binary-search-tree/65c4f3258d2e4cdacc919dfd.md

latest903 B
Original Source

--description--

At the end of your _insert method, after the insertion process is complete, return the current node to update the tree structure at the higher levels of the recursive call stack.

--hints--

You should return the current node outside the conditional blocks.

js
({ test: () => assert.match(code, /^\s{8}return\s+node/m) })

--seed--

--seed-contents--

py
class TreeNode:
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None

class BinarySearchTree:
    def __init__(self):
        self.root = None

--fcc-editable-region--    
    def _insert(self, node, key):
        if node is None:
            return TreeNode(key)
        if key < node.key:
            node.left = self._insert(node.left, key)
        elif key > node.key:
            node.right = self._insert(node.right, key)

--fcc-editable-region--