public static IHuffmanNode insertIntoTree(IHuffmanNode rootNode, LinkedList<IHuffmanWord> list) {
        rootNode = rootNode == null ? new Node() : rootNode;
        for (IHuffmanWord word : list) {
            IHuffmanNode curNode = rootNode;
            int[] code = word.getOutputWord();
            int relBits = word.getRelevantOutputBits();

            int startBit = relBits % 32 - 1;
            for (int subCode : code) {
                for (int i = startBit; i >= 0; i--) {
                    int bit = (subCode >>> i) & 1;
                    if (bit == 0 && curNode.getLeft() == null)
                        ((Node) curNode).setLeft(new Node());
                    if (bit == 1 && curNode.getRight() == null)
                        ((Node) curNode).setRight(new Node());
                    curNode = bit == 0 ? curNode.getLeft() : curNode.getRight();
                }
                startBit = 31;
            }
            ((Node) curNode).setWord(word);
        }
        return rootNode;
    }