📄 类继承实现方法.h
字号:
#ifndef SECLEAFNINTL_H
#define SECLEAFNINTL_H
class VarBinNode{
public:
virtual bool isLeaf()=0;
virtual void trav()=0;
};
class LeafNode:public VarBinNode{
private:
int var;
public:
LeafNode(const int& val)
{var=val;}
bool isLeaf(){return true;}
int value(){return var;}
void trav(){cout<<"Leaf:"<<value()<<endl;}
};
class IntlNode:public VarBinNode{
private:
VarBinNode* lc;
VarBinNode* rc;
char opx;
public:
IntlNode(const char& op,VarBinNode* l,VarBinNode* r)
{ opx=op; lc=l; rc=r; }
bool isLeaf(){return false;}
VarBinNode* leftchild(){return lc;}
VarBinNode* rightchild(){return rc;}
char value(){return opx;}
void trav(){
cout<<"Internal:"<<value()<<endl;
if(leftchild()!=NULL)leftchild()->trav();
if(rightchild()!=NULL)rightchild()->trav();
}
};
void traverse(VarBinNode *subroot){
if(subroot!=NULL)subroot->trav();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -