protected void createTree(LinkedHashMap<BitSet, Integer> set1){
        if (set1.size() <= 1){
            return;
        }
        LinkedHashMap<BitSet, Integer> part1 = new LinkedHashMap<>();
        LinkedHashMap<BitSet, Integer> part2 = new LinkedHashMap<>();
        Iterator<Entry<BitSet, Integer>> it = set1.entrySet().iterator();
        int sum = getSum(it);
        int partSum = 0;
        it = set1.entrySet().iterator();
        
        while (it.hasNext()) {
            Entry<BitSet, Integer> pairs = it.next(); 
            BitSet bsDivide = pairs.getKey();
            partSum += pairs.getValue();
            
            if (partSum >= sum-partSum){
                Iterator<Entry<BitSet, Integer>> it1 = set1.entrySet().iterator();
                BitSet bs; 
                if (it1.hasNext()){
                    do{ 
                        bs = it1.next().getKey(); 
                        Integer value = set1.get(bs); 
                        part1.put(bs, value);
                        CodeStruct codeStruct = tree.get(bs);
                        BitSet code = codeStruct.code;
                        code.set(iteration, false);
                        tree.get(bs).length = (short) (iteration + 1);
                        tree.get(bs).code = code;
                        if (!it.hasNext())
                            break;
                    }while(bs != bsDivide);
                    
                    do{ 
                        if (it1.hasNext()){
                            bs = it1.next().getKey();
                            Integer value = set1.get(bs);
                            part2.put(bs, value);
                            CodeStruct codeStruct = tree.get(bs);
                            BitSet code = codeStruct.code;
                            code.set(iteration, true);
                            tree.get(bs).length = (short) (iteration + 1);
                            tree.get(bs).code = code;
                        }
                    }while(it1.hasNext());
                    break;
                }
            }
        }
        iteration++;
        short iter = iteration;
        createTree(part1);
        iteration = iter;
        createTree(part2);
    }