huffman(greedy)
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)的更多相关文章
- 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 ...
- Greedy is Good
作者:supernova 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=greedyAlg Joh ...
- [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 ...
- 贪婪算法(Greedy Algorithm)
Greedy Algorithm <数据结构与算法--C语言描述> 图论涉及的三个贪婪算法 Dijkstra 算法 Prim 算法 Kruskal 算法 Greedy 经典问题:coin ...
- 哈夫曼(huffman)树和哈夫曼编码
哈夫曼树 哈夫曼树也叫最优二叉树(哈夫曼树) 问题:什么是哈夫曼树? 例:将学生的百分制成绩转换为五分制成绩:≥90 分: A,80-89分: B,70-79分: C,60-69分: D,<60 ...
- USACO . Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- (转载)哈夫曼编码(Huffman)
转载自:click here 1.哈夫曼编码的起源: 哈夫曼编码是 1952 年由 David A. Huffman 提出的一种无损数据压缩的编码算法.哈夫曼编码先统计出每种字母在字符串里出现的频率, ...
- [老文章搬家] 关于 Huffman 编码
按:去年接手一个项目,涉及到一个一个叫做Mxpeg的非主流视频编码格式,编解码器是厂商以源代码形式提供的,但是可能代码写的不算健壮,以至于我们tcp直连设备很正常,但是经过一个UDP数据分发服务器之后 ...
- jpeg huffman coding table
亮度DC系数的取值范围及序号: 序号(size) 取值范围 0 0 1 - ...
随机推荐
- 【awk】提取文件第一列
生信数据文件一般是按列分开的,如果我们只想简单的提取一列而不是费尽周折写个程序提取哪一列的话,awk作为一个非常好用的文档处理工具,我们现在来简单看一下他的一些功能: awk '{print $1}' ...
- auto关键字
使用前: #include<string> #include<vector> int main() { std::vector<std::string> vs; f ...
- onblur 事件
onblur 事件 Event 对象 定义和用法 onblur 事件会在对象失去焦点时发生. 语法 onblur="SomeJavaScriptCode" 参数 描述 SomeJa ...
- 【2.0】SpringBoot多环境yml文件配置
一.使用Spring Boot Profiles 1. 使用yml文件 首先,我们先创建一个名为 application.yml的属性文件,如下: server: port: 8080 my: nam ...
- BZOJ5487: [Usaco2018 Dec]Cowpatibility
Description 研究证明,有一个因素在两头奶牛能否作为朋友和谐共处这方面比其他任何因素都来得重要--她们是不是喜欢同 一种口味的冰激凌!Farmer John的N头奶牛(2≤N≤50,000) ...
- 编码原则 之 Explicit Dependencies Principle
Explicit Dependencies Principle The Explicit Dependencies Principle states: Methods and classes shou ...
- Mybatis自动生成,针对字段类型为text等会默认产生XXXXWithBlobs的方法问题
需要修改generatorConfiguration.xml,里面的table加属性:<table tableName="t_ticketcase" domainObject ...
- MapReduce 踩坑 - hadoop No FileSystem for scheme: file/hdfs
一.场景 hadoop-3.0.2 + hbase-2.0.0 一个mapreduce任务,在IDEA下本地提交到hadoop集群可以正常运行. 现在需要将IDEA本地项目通过maven打成jar包, ...
- 调试.vs08
1.vs2008 在调试的时候出现如下状况: 关键字:“不会命中断点.源代码与原始版本不同.”(ZC:我的情况是 main.cpp里面的断点是有效的,但是执行到另一个cpp里面时 这个文件里面的断点都 ...
- 学习笔记69—金蝶财务软件安装教程(KIS12.3,win10)
****************************************************** 如有谬误,请联系指正.转载请注明出处. 联系方式: e-mail: heyi9069@gm ...