我是新来的c#我刚刚完成了一个huffman tree
,现在下一步就是让它generic
我的意思是这个symbol
应该为每个data type
工作。由于我是c#初学者,我需要一些基本的想法来做到这一点。在c#中使用泛型创建树#
我的霍夫曼树由3个类组成。类霍夫曼,节点和MyClass的(其中包含的主要功能),其中freq
是时代的symbol
重复下面给出它们的结构数量:
namespace final_version_Csharp
{
public Class Huffman
{
public classNode
{
public Node next, left, right;
public int symbol;
public int freq;
}
public Node root;
}
public void huffman_node_processing()
{
//done the addition of two minimum freq here
}
public void GenerateCode(Node parentNode, string code)
{
//done the encoding work here
}
public class MyClass
{
public static void Main(string[] args)
{
Huffman ObjSym = new Huffman(args); //object creation by reading the data fron a file at sole argument
//All other methods are here
ObjSym.huffman_node_processing(); //this for adding the two minimum nodes
ObjSym.GenerateCode(ObjSym.root, ""); //this for encoding
}
}
}
可能有人请帮助我使这个“符号”的工作所有的数据类型,如“短”,“长”等
当你说generic时,你的意思是一个节点可以在同一棵树中有一个int符号和一个字符串符号,或者你希望能够创建一个符号总是相同的树(例如字符串) –
@BobVale实际上我正在读取一个二进制文件,以创建符号的频率(可能是1110111的形式)。 “符号”必须适用于1字节或2字节等。你现在明白了吗? – Sss