📄 hufftree.h
字号:
//霍夫曼树类
#ifndef HUFFTREE_H
#define HUFFTREE_H
class HuffTree{
private:
HuffNode* theRoot;
public:
HuffTree(){}
~HuffTree(){
}
void addleaf(char &val,int freq){
theRoot=new LeafNode(val,freq);
}
HuffTree(HuffTree* l,HuffTree* r){
theRoot=new IntlNode(l->root(),r->root());
}
HuffNode* root(){return theRoot;}
int weight(){return theRoot->weight();}
void traverse(HuffNode *subroot){
if(subroot==NULL)return;
cout<<subroot->weight()<<" ";
traverse(subroot->left());
traverse(subroot->right());
}
void encode(HuffNode *subroot,huffcode *hcode,int& hcodecount,char*path,int &pathcount){
if(subroot->isLeaf()){
path[pathcount]=NULL;
strcpy(hcode[hcodecount].code,path);
hcode[hcodecount++].letter=((LeafNode*)subroot)->val();
return;
}
path[pathcount++]='0';
encode(subroot->left(),hcode,hcodecount,path,pathcount);
pathcount--;
path[pathcount++]='1';
encode(subroot->right(),hcode,hcodecount,path,pathcount);
pathcount--;
}
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -