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 - ...
随机推荐
- 看懂MSSQL执行计划,分析SQL语句执行情况
打开SQL执行计划窗口 执行计划的图表是从右向左看的 SQL Server有几种方式查找数据记录 [Table Scan] 表扫描(最慢),对表记录逐行进行检查 [Clustered Index Sc ...
- SpringMVC 允许跨域访问 也可以选择限制指定IP 允许访问 对象的数据传输
java ajax
- 给zabbix添加percona监控模板
简单说明一下给zabbix添加的percona的监控模板. 在percona官方网站有说明怎么安装,这里记录下步骤.首先搭建好的zabbix环境. 监控插件连接 : 链接:https://pan.ba ...
- docker性能测试
测试环境: 操作系统:CentOS7.openstack nova-docker启动的centos7.openstack环境启动的centos7虚拟机 CPU:Intel(R) Xeon(R) CPU ...
- docker启动容器报错: could not synchronise with container process: not a directory
错误现象 在运行容器时,出现以下错误 [root@localhost test]# docker run -it -d -v $PWD/test.txt:/mydir mytest fd44cdc55 ...
- QThread使用——关于run和movetoThread的区别
QThread 使用探讨 2010-10-23 00:30 注意:本文停止更新,请优先考虑 Qt 线程基础(QThread.QtConcurrent等) dbzhang800 2011.06.18 Q ...
- js 过滤器
,,]; ary[] = ; ary.filter(function(x) { return x === undefined; }); // A. [undefined x 7] // B. [0, ...
- VUE本身是不支持IE的,可用babel-polyfill解决
一般来说VUE本身是不支持IE的,但是可以用特殊的方法来解决,亲测可用第一步:下载插件 cnpm install --save babel-polyfill第二步:入口文件main.js引入( imp ...
- LINQ解析
Linq 是什么? Linq是Language Integrated Query的缩写,即“语言集成查询“的意思,Linq的提出就是为了提供一种跨各种数据源统一查询方式,主要包含四种组件:Linq t ...
- webpack点滴
一个比较完整的webpack的配置,自己配置不断更新. const path = require('path') const configs = require('./configs/') const ...