简体   繁体   English

在Python 3.x中遍历霍夫曼代码树

[英]Traversing a Huffman Code Tree in Python 3.x

I am trying to generate inorder and preorder traversals of a Huffman Code Tree in python. 我试图在python中生成霍夫曼代码树的有序和预遍历遍历。 I seem to have hit a wall though. 我好像撞墙了。 I need to generate the traversals and write them to corresponding files, and then create a binary path to the locations of each node and output that to a file as well. 我需要生成遍历并将其写入相应的文件,然后创建指向每个节点位置的二进制路径并将其输出到文件中。 Here is what I have so far 这是我到目前为止的

Here is a PDF file of a lecture given for a course at Harvard (easily found by simple google search.) It provides examples, explanations, pictures of trees, and code to do what you are asking to do. 这是哈佛课程的讲座的PDF文件(可通过简单的Google搜索轻松找到。)它提供示例,解释,树木图片和代码来完成您要做的事情。 But the code is in Java. 但是代码是用Java编写的。 However, you should be able to translate these short programs to Python easily. 但是,您应该能够轻松地将这些简短程序转换为Python。 Or just code Python directly from the explanations. 或者直接从解释中编写Python代码。 It includes Huffman trees. 它包括霍夫曼树。

http://www.fas.harvard.edu/~cscie119/lectures/trees.pdf http://www.fas.harvard.edu/~cscie119/lectures/trees.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM