title: Homework: Return the least element in the set greater than given element BST
body: <p>So I've been stuck for hours trying to figure out this problem.</p>
  
  <p>Given a randomly generated BST and using the method header:
  <code>public E higher(E elt)</code></p>
  
  <p>Where <code>elt</code> is a randomly generated value within the tree's range, I need to find the least element in the set greater than <code>elt</code>.</p>
  
  <p>Nodes contain left links and right links, but no parent link. </p>
  
  <p>The tree in the linked image reads with the root being the leftmost node
  <a href="http://i.stack.imgur.com/sEZPn.png" rel="nofollow">BST</a>.</p>
  
  <p>So if <code>elt</code> is 27, then I want to return the node containing 28.</p>
  
  <p>I need to run this in O(logn) time, and everything I've tried has not worked.
  I'm not looking for someone to do my homework for me, but I have no clue what to do at this point.</p>
  
  <p>I can provide more detail and source code if it's needed.</p>
  
  <p>Edit: I'll put this here, though it's woefully inadequate. I feel as though this would be easier if I could do this recursively but I can't think of a way to do that.</p>
  
  <pre><code>Node n = root;
      //need to get this into a loop somehow and break out when I've found
      //the right value
      int c = myCompare(elt, ((E) n.data));
      if (c &lt; 0) {
          n = n.left;
          //now I need to compare this against any children
      } else if (c &gt; 0) {
          n = n.right;
          //now I need to compare this against any children
      }
      return ((E)n.data);
  </code></pre>