title: Huffman coding from frequency array (in Java)
body: <p>I have a problem with my Huffman code. In the main method I input an Integer array containing the frequency of the Symbols. It should print out each Symbol and its Huffman code, but I think something is wrong</p>
  
  <p>In main:</p>
  
  <pre><code>int[] histo = new int[]{8, 65, 124, 55, 2, 1, 0, 1};
  System.out.println("Codage de Huffman:");
  String[] huffman = huffman(histo);
  for (int i = 0; i &lt; huffman.length; i++) {
      if (histo[i] &gt; 0) {
          System.out.println(i + "] " + huffman[i]);
      }
  }
  </code></pre>
  
  <p>Now in huffman code:</p>
  
  <pre><code>public static String[] huffman(int[] histo) {
      String[] codage = new String[histo.length];
      int valeur1;
      int valeur2;
      int index1 = 0;
      int index2 = 0;
      for (int i = 0; i &lt; histo.length; i++) {
          codage[i] = new String();
      }
  
      do {
          valeur1 = Integer.MAX_VALUE;
          valeur2 = Integer.MAX_VALUE;
          for (int i = 0; i &lt; histo.length; i++) {
              if (histo[i] &gt; 0) {
                  if (histo[i] &lt; valeur1) {
                      valeur2 = valeur1;
                      valeur1 = histo[index1 = i];
                  } else if (histo[i] &lt; valeur2) {
                      valeur2 = histo[index2 = i];
                  }
              }
          }
          histo[index1] = 0;
          histo[index2] += valeur1;
          codage[index1] = codage[index1] + "0";
          codage[index2] = codage[index2] + "1";
      } while (valeur2 != Integer.MAX_VALUE);
  
      return codage;
  
  }
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre><code>0] 0
  1] 0
  2] 0
  3] 111101
  4] 0
  5] 0
  7] 110
  </code></pre>