CSC403: Put: Embrace null [6/9] Previous pageContentsNext page

    public void put (int key) {
        root = put (root, key);
    }
    private static Node put (Node x, int key) {
        if (x == null) return new Node (key);
        //...
    }

To get rid of too many base cases, we must embrace null.

One method call responsible for creating the node.

A different method call responsible for putting it in the right place.

This works if we insert one key into the empty tree

Previous pageContentsNext page