对霍夫曼来说...... [英] On to huffman...

查看:79
本文介绍了对霍夫曼来说......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢 http://www.thescripts.com/forum/thread686347提供的帮助。关于字符数计划的html ,我现在可以继续完成霍夫曼代码了。不幸的是,我仍然是Java的新手,并且在开始时又需要帮助。


这里不会要求整个代码因为它违反规则而且它不会帮助我学习语言。我知道如果我使用C ++,我可以使用STL中存在的堆容器但是java有类似的东西吗?


试图google" java heap容器"但我得到的只是一些内存不足的错误...


仍将进行搜索,我希望有人能指出我正确的方向。


在此先感谢:)

Thanks to the help over at http://www.thescripts.com/forum/thread686347.html on the character count program, I can now move onto getting the huffman code done. Unfortunately I am still rather new to Java and would again need help on getting started.

Not gonna ask for the whole code here cos its against the rules and its not gonna help me learn the language. I know that if I use C++, I can use the heap container which is present in the STL but for java is there something like that?

Went to try to google "java heap container" but all I got was some out of memory error...

Will still carry on searching and I hope someone will point me in the right direction.

Thanks In Advance :)

推荐答案


感谢 http://www.thescripts.com/forum/thread686347.html 关于字符数计划,我现在可以移动了完成霍夫曼代码。不幸的是,我仍然是Java的新手,并且在开始时又需要帮助。


这里不会要求整个代码因为它违反规则而且它不会帮助我学习语言。我知道如果我使用C ++,我可以使用STL中存在的堆容器但是java有类似的东西吗?


试图google" java heap容器"但我得到的只是一些内存不足的错误...


仍将进行搜索,我希望有人能指出我正确的方向。


在此先感谢:)
Thanks to the help over at http://www.thescripts.com/forum/thread686347.html on the character count program, I can now move onto getting the huffman code done. Unfortunately I am still rather new to Java and would again need help on getting started.

Not gonna ask for the whole code here cos its against the rules and its not gonna help me learn the language. I know that if I use C++, I can use the heap container which is present in the STL but for java is there something like that?

Went to try to google "java heap container" but all I got was some out of memory error...

Will still carry on searching and I hope someone will point me in the right direction.

Thanks In Advance :)



如果你想到一个霍夫曼树有两种类型的节点:简单字符

节点;它们是树的叶子,以及内部节点,它们是霍夫曼树的组合

节点。


两个节点都可以返回它们frequency:字符(叶子)节点只返回它们代表的字符的频率,组合节点返回子节点频率的总和。


如果X'的频率小于Y'的频率,则节点X小于节点Y.

这使得这些节点非常适合存储它们一个SortedSet(TreeSet)。

排序集相当于你的堆结构。


用这样的SortedSet构建一个Huffman树很简单:简单组合

具有最低频率的两个节点,从集合中删除它们并再次将新创建的组合节点添加到集合中。继续前进,直到该集合中剩下一个节点只有

。那将是霍夫曼树的根源。


抽象节点类和两个扩展类(字符节点和

组合节点)都是这是必要的。


亲切的问候,


Jos

If you think of a Huffman tree there are two types of nodes: simple character
nodes; they are the leaves of the tree, and ''internal'' nodes which are the combined
nodes of the Huffman tree.

Both nodes can return their frequency: character (leaf) nodes simply return the
frequence of the character they represent and the combined nodes return the
sum of the frequencies of their child nodes.

A node X is smaller than a node Y if X''s freqency is smaller than Y''s frequency.
This makes those nodes ideal to store them in a SortedSet (TreeSet).
The sorted set is the equivalent of your heap structure.

Building a Huffman tree out of such a SortedSet is breeze: simply combine
the two nodes with the lowest frequency, remove them from the set and add the
newly created combined node to the set again. Keep going until there''s only
one node left in the set. That''ll be the root of the Huffman tree.

An abstract node class and two extending classes (character node and a
combined node) are all that is needed.

kind regards,

Jos



如果你想到一个霍夫曼树,有两种类型的节点:简单字符

节点;它们是树的叶子,以及内部节点,它们是霍夫曼树的组合

节点。


两个节点都可以返回它们frequency:字符(叶子)节点只返回它们代表的字符的频率,组合节点返回子节点频率的总和。


如果X'的频率小于Y'的频率,则节点X小于节点Y.

这使得这些节点非常适合存储它们一个SortedSet(TreeSet)。

排序集相当于你的堆结构。


用这样的SortedSet构建一个Huffman树很简单:简单组合

具有最低频率的两个节点,从集合中删除它们并再次将新创建的组合节点添加到集合中。继续前进,直到该集合中剩下一个节点只有

。那将是霍夫曼树的根源。


抽象节点类和两个扩展类(字符节点和

组合节点)都是这是必要的。


亲切的问候,


Jos
If you think of a Huffman tree there are two types of nodes: simple character
nodes; they are the leaves of the tree, and ''internal'' nodes which are the combined
nodes of the Huffman tree.

Both nodes can return their frequency: character (leaf) nodes simply return the
frequence of the character they represent and the combined nodes return the
sum of the frequencies of their child nodes.

A node X is smaller than a node Y if X''s freqency is smaller than Y''s frequency.
This makes those nodes ideal to store them in a SortedSet (TreeSet).
The sorted set is the equivalent of your heap structure.

Building a Huffman tree out of such a SortedSet is breeze: simply combine
the two nodes with the lowest frequency, remove them from the set and add the
newly created combined node to the set again. Keep going until there''s only
one node left in the set. That''ll be the root of the Huffman tree.

An abstract node class and two extending classes (character node and a
combined node) are all that is needed.

kind regards,

Jos



谢谢你解释......会去尝试一下......想想我现在有一个大概的想法...


再次非常感谢:)

Thanks for the explaination... will go and try it out... think I have a rough idea how now...

Many thanks again :)


关于compareTo的问题()


所以在这种情况下,我需要用它来比较两个节点,以便对sortedSet进行排序。


看起来像这样吗?

question about compareTo()

so in this case, I would then need to use that to compare two nodes for sorting for the sortedSet.

would it look something like this?

展开 | 选择 | W rap | 行号


这篇关于对霍夫曼来说......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆