present a file by binary character code,let the less characters can be presented simplier.

 package greedy;

 import java.util.Iterator;
import java.util.LinkedList; public class huffman {
private static class Node{
private Node left ;
private Node right ;
private int freq;
public Node(Node left,Node right,int freq){
this.left = left;this.right = right; this.freq = freq;
}
} public Node Huffman(LinkedList<Node> list){
int n = list.size();
for(int i = 1;i <= n-1;i++){
Node x = list.removeFirst();
Node y = list.removeFirst();
Node node = new Node(x,y,x.freq + y.freq);
for (int j = 0;j < list.size() - 1;j++){
if(node.freq >= list.get(j).freq && node.freq <= list.get(j+1).freq){
list.add(j+1,node);
}
else if( j+1 == list.size() - 1){
list.addLast(node);
} } }
return list.getFirst(); } }

huffman(greedy)的更多相关文章

  1. hdu 1053 (huffman coding, greedy algorithm, std::partition, std::priority_queue ) 分类: hdoj 2015-06-18 19:11 22人阅读 评论(0) 收藏

    huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commente ...

  2. Greedy is Good

    作者:supernova 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=greedyAlg Joh ...

  3. [Optimization] Greedy method

    Given two sequences of letters A and B, find if B is a subsequence of A in thesense that one can del ...

  4. 贪婪算法(Greedy Algorithm)

    Greedy Algorithm <数据结构与算法--C语言描述> 图论涉及的三个贪婪算法 Dijkstra 算法 Prim 算法 Kruskal 算法 Greedy 经典问题:coin ...

  5. 哈夫曼(huffman)树和哈夫曼编码

    哈夫曼树 哈夫曼树也叫最优二叉树(哈夫曼树) 问题:什么是哈夫曼树? 例:将学生的百分制成绩转换为五分制成绩:≥90 分: A,80-89分: B,70-79分: C,60-69分: D,<60 ...

  6. USACO . Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...

  7. (转载)哈夫曼编码(Huffman)

    转载自:click here 1.哈夫曼编码的起源: 哈夫曼编码是 1952 年由 David A. Huffman 提出的一种无损数据压缩的编码算法.哈夫曼编码先统计出每种字母在字符串里出现的频率, ...

  8. [老文章搬家] 关于 Huffman 编码

    按:去年接手一个项目,涉及到一个一个叫做Mxpeg的非主流视频编码格式,编解码器是厂商以源代码形式提供的,但是可能代码写的不算健壮,以至于我们tcp直连设备很正常,但是经过一个UDP数据分发服务器之后 ...

  9. jpeg huffman coding table

    亮度DC系数的取值范围及序号:                                                               序号(size) 取值范围 0 0  1 - ...

随机推荐

  1. Nginx+keepalived 双机热备(主从模式)

    负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网站健康持续运行.关于负载均衡介绍,可以参考:linux负载 ...

  2. 用javaScript获取页面元素值

    用JavaScript获取页面元素常见的三种方法:                                                           getElementById() ...

  3. 各种数据库连接字符串 -- c#

    sqlite : connectionString="Data Source=|DataDirectory|\databasename.db;Pooling=true;FailIfMissi ...

  4. java4/9 异常处理

  5. Centos7 升级 Ruby

    Centos7通过yum 安装的Ruby 是2.0版本.版本较低,需要升级到2.5以上版本. #yum 安装ruby yum install ruby #查看ruby版本 ruby -v 以下开始升级 ...

  6. Excel 表格查找重复数据,去重复统计

    找出表格是否有重复数据: =IF(AND(G20=G19,D20=D19),"是","否") 筛选移除[重复的数据]然后开始统计 =SUBTOTAL(9,E2: ...

  7. [POJ268] Prime Distance(素数筛)

    /* * 二次筛素数 * POJ268----Prime Distance(数论,素数筛) */ #include<cstdio> #include<vector> using ...

  8. Character流与Byte流的区别(转)

    Character流与Byte流的区别是 A) 每次读入的字节数不同 B) 前者带有缓冲,后者没有C) 前者是字符读写,后者是字节读写 D) 二者没有区别,可以互换使用 Java的流操作分为字节流和字 ...

  9. 【NET Core】事务TransactionScope

    .NET FrameWork时期: TransactionScope是FCL System.Transactions命名空间下的分布式事务组件,它默认为本地事务,当系统有需要时可以自动提升为分布式事务 ...

  10. 如何在nginx容器中使用ping、nslookup、ip、curl 等工具?

    Nginx镜像太精简了,启动一个容器进行测试时,常用的网络工具都没有,可以使用下面的命令进行安装.也可以直接起一个busybox容器进行测试. apt update #ping apt install ...