title: Iterative binary tree insert function in Java
body: <p>I'm making a comparison between recursive and iterative algorithms, and I am currently trying to create an iterative "insert()" method to place things into my binary tree. (I've made my own tree structure). The code is as follows.</p>
  
  <pre><code>public void insert(Object objectToInsert) {
      root = insert(objectToInsert, root);
  }
  
  private Node insert(Object objectToInsert, Node tree) {
      Node nodeToInsert = new Node(objectToInsert);
      boolean inserting = true;
      while (inserting) {
          if (tree == null) {
              tree = nodeToInsert;
              inserting = false;
              treeSize++;
          } else {
              if (nodeToInsert.getUniqueID() &lt; tree.getUniqueID()) {
                  tree = tree.getLeft();
              } else {
                  tree = tree.getRight();
              }
          }
      } // end while loop
      return tree;
  }
  </code></pre>
  
  <p>I feel like I'm missing something really simple here?
  Thank you!</p>
  
  <p>Heads up:
  Object() is a class I made - not Java's native class.</p>