📄 huffnode.h
字号:
////////////////////////////////////////////////
//基类结点
#ifndef HUFFNODE_H
#define HUFFNODE_H
class HuffNode
{
public:
virtual int weight()=0;
virtual bool isLeaf()=0;
virtual HuffNode* left()=0;
virtual HuffNode* right()=0;
virtual void setLeft(HuffNode*)=0;
virtual void setRight(HuffNode*)=0;
};
////////////////////////////////////////////////
//叶结点
class LeafNode:public HuffNode
{
private:
FreqPair * it;
public:
LeafNode(char& val,int freq)
{
it=new FreqPair(val,freq);
}
int weight (){return it->weight();}
char val(){return it->val();}
bool isLeaf(){return true;}
HuffNode* left(){
return NULL;
}
HuffNode* right(){
return NULL;
}
void setLeft(HuffNode*){}
void setRight(HuffNode*){}
};
///////////////////////////////////////////////
//枝结点
class IntlNode:public HuffNode{
private:
HuffNode * lc;
HuffNode * rc;
int wgt;
public:
IntlNode(HuffNode* l,HuffNode* r){
wgt=l->weight()+r->weight();
lc=l;
rc=r;
}
int weight(){return wgt;}
bool isLeaf(){return false;}
HuffNode* left(){return lc;}
HuffNode* right(){return rc;}
void setLeft(HuffNode *b){lc=(HuffNode*)b;}
void setRight(HuffNode*b){rc=(HuffNode*)b;}
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -