title: How to find max value in a binary tree
body: <p>I have to complete the method <strong>maxElem(Node node)</strong> in such a way that the method <strong>maxElem()</strong> returns the maximum value contained in a binary tree. </p>
  
  <p>How can I do that? I do not know how to do that..</p>
  
  <pre><code>public class BinaryTree {
  
      protected class Node {
          protected Integer element;
          protected Node left;
          protected Node right;
  
          Node(int element) {
              this.element = element;
              left = right = null;
          }
  
          Node(int element, Node left, Node right) {
              this.element = element;
              this.left = left;
              this.right = right;
          }
  
      } //end Node class
  
      public class NodeReference {
          private Node node;
  
          private NodeReference(Node node) {
              this.node = node;
          }
  
          public int getElement() {
              return node.element;
          }
  
          public void setElement(int e) {
              node.element = e;
          }
      }
  
      protected Node root;
  
      public BinaryTree() {
          root = null;
      }
  
      private class BoolNode {
  
          boolean found; 
          Node node;
  
          BoolNode(boolean found, Node node) {
              this.found = found;
              this.node = node;
          }
      }
  
      public int maxElem() {
          if(root == null) 
              throw new IllegalStateException("Empty tree.");
          return maxElem(root);
      }
  
  
      private static int max3(int x, int y, int z) {
          return max(x, max(y, z));
      }
  
      private int maxElem(Node node) {
          //...
      }
  
  }
  </code></pre>
  
  <p>Thanks a lot!</p>