Hello I am attempting to build my own TreeMap data structure. I have an add method that passes a Key and Value, I then have another method called insert that will recursively add the node to the tree. I keep getting a stackoverflow error. 
I am unsure how to resolve this error I've re-written my insert method a few times and tried passing parent Nodes into the method. Can someone explain the logic behind what should be passed into the insert method or how my code may possibly still work? 

Is the best option here to utilize recursion to add nodes to my tree? or can I accomplish the same thing with a while loop?

Any help is appreciated thank you!

```
public boolean add(K key, V value) 
{

 //root is declared as a class level variable in my Map class 

if (root == null) {

        curSize++;
        root = new Node(key, value);
        root.parent = null;
        return true;
    }
    //Creating a new Node with the passed arguments
    Node n = new Node(key, value);
    Node curNode = root;

//Calling insert method

    if (curNode.insert(n, curNode)) {
        curSize++;
        return true;
    } else {
        return false;
    }
}

protected boolean insert(Node curNode, K key, V value) {

        int result = key.compareTo(curNode.key);
        boolean x = false;

        if (curNode.L == null && result < 0) {
            curNode.L = new Node(key, value);
            x = true;
        }
        if (curNode.R == null && result > 0) {
            curNode.R = new Node(key, value);
            x = true;
        }
        if (result == 0)
            x = false;

        if (curNode.L != null && result < 0)
            insert(curNode.L, key, value);
        if (curNode.R != null && result > 0)
            insert(curNode.R, key, value);

        return x;

    }
//My Node class with its constructor, Insert method is inside this class.

 private class Node {
    public Node L;
    public Node R;
    public K key;
    public V value;
    public Node parent;

    public Node(K k, V v) {
        this.L = null;
        this.R = null;
        this.key = k;
        this.value = v;
    }

```