晚场电影 2021-06-05 20:28 采纳率: 66.7%
浏览 67
已结题

JAVA /一段很简单的代码片段为啥子会出错了呢

这是一段没有写完的哈夫曼树压缩解压缩文件的代码,但是其中的PriorityBlockingQueue数据结构中的comparator接口出问题了。。。 

package Controller.Huffman_tree;

import javax.swing.tree.TreeNode;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.PriorityBlockingQueue;


public class buildTree {

    public static class TreeNode  {

        int weight;
        Byte data;
        TreeNode lClild;
        TreeNode rChild;

        public void setWeight(int weight) {
            this.weight = weight;
        }

        public void setData(Byte data) {
            this.data = data;
        }

        public TreeNode() {
        }

        public TreeNode(int weight, Byte data) {
            this.weight = weight;
            this.data = data;
        }

        @Override
        public String toString() {
            return "TreeNode{" +
                    "weight=" + weight +
                    ", data=" + data.toString() +
                    ", lClild=" + lClild +
                    ", rChild=" + rChild +
                    '}';
        }

    }

    public static Queue<TreeNode> pq;

    public static Byte [] bytes;

    public static void main(){

    }

    public static void creatingLeafs(){
        Map<Byte,Integer> map=new Hashtable<>();
        pq=new PriorityBlockingQueue<TreeNode>(101,
                new Comparator<TreeNode>() {
                    @Override
                    public int compare(TreeNode o1, TreeNode o2) {
                        return o1.weight - o2.weight;
                    }
                }
        );
        for(Byte b:bytes){
        if(map.containsKey(b)){
            map.put(b,map.get(b)+1);
        }
        else{
            map.put(b,1);
        }
        for(Map.Entry<Byte,Integer> it:map.entrySet()){
            TreeNode node=new TreeNode(it.getValue(),it.getKey());
            pq.add(node);
        }
        }
    }

    public static TreeNode buildTree(){
        while(pq.size()>1){
            TreeNode new_node=new TreeNode();


        }

    }


}
  • 写回答

6条回答 默认 最新

  • 小P聊技术 2021-06-05 21:09
    关注

    报错

    评论

报告相同问题?

悬赏问题

  • ¥15 easypoi导出复杂excel
  • ¥20 C++初高中竞赛题,devc++可以通过的
  • ¥60 二次元手游日常任务自动化代肝(相关搜索:自动化)
  • ¥15 mysql将查询的结果作为动态列名怎么实现
  • ¥50 python自动地图截图脚本
  • ¥20 瑞萨RA4M1芯片刷写为arduino r4 minima
  • ¥15 fastreport怎么判断当前页数
  • ¥15 Kylin-Desktop-V10-GFB-Release-JICAI_02- 2207-Build14-ARM64.iso有没有这个版本的系统啊
  • ¥15 能不能通过蓝牙将传感器数据传送到手机上
  • ¥20 100元python和数据科学实验项目