title: Returning multiple values from a recursive function
body: <p>I have this problem where I have to convert a decimal number to binary and then store the bits in a linked list where the head node is the most significant bit and the last node is the least significant bit. Solving the problem itself is actually easy as you only need to keep taking the modulo of 2 recursively and add the result in the list until the decimal number becomes 0.</p>
  
  <p>Where I'm stuck is that I have to write the function such that it returns a pair of number, (whether an array or a list) of the most significant bit and the last significant bit. 
  i.e: Inputting 14 in the function would return (1, 0), since 14 is 1110 in binary. </p>
  
  <p>I do have access to the MSB and LSB easily(getFirst(), getLast()). </p>
  
  <p>The function can only take one argument which is the decimal number.</p>
  
  <p>Currently I  have this current code:</p>
  
  <pre><code>public static void encodeBin(int n) {
      if(n == 0) return; //Base case
      else {
          if(n % 2 == 0)
              theList.addFirst(0);
          else
              theList.addFirst(1);
          encodeBin(n / 2);
      }
      // return?
  }
  </code></pre>
  
  <p>The problem is I can't figure out how return the 2 values. Haveing a return value means I can't call encodeBin() by itself.</p>
  
  <p>Moreover, where should I create the list? If I put something like <code>List&lt;Integer&gt; = new LinkedList&lt;Integer&gt;()</code> at the very beginning of the function, then each time the function calls itself, it creates a new list and adds the bits in THAT new list not the original right?(The list created from when the function is called the first time)</p>
  
  <p>Anybody knows how to solve this?</p>