title: Turning a Binary Tree to a sorted array
body: <p>Is there a way to turn a Binary to a sorted array without having to traverse the tree for every array index?</p>
  
  <pre><code>Node root;
  Node runner;
  int current_smallest;
  
  void findsmallest(Node root){
      //Pre-order traversal
      if(root == null){
          return;
      }else{
          runner = root;
          if(current_smallest == null){
              current_smallest = runner.element;
          }else{
              if(current_smallest &gt; runner.element){
              current_smallest = runner.element;
              }
          }
          findsmallest(runner.left);
          findsmallest(runner.right);
      }   
  }
  
  void fill_array( int [] array ){
  
      for(int i =0; i &lt; array.length(); i++){
          findsmallest(root);
          array[i] = current_smallest;
      }
  } 
  </code></pre>
  
  <p>As you can see this can be take a long time if there are a lot of nodes in the tree.
  Btw, I forgot to show that the whole tree would have to be traversed at the start to get the length of the array.</p>