#ifndef _MyTreeNode_h_
#define _MyTreeNode_h_
#include <iostream>
#include <string>
using namespace std;
class MyTreeNode {
public:
char data;
int weight;
int isfather;
bool isBianLi;
char code;
string codes;
MyTreeNode* left;
MyTreeNode* right;
MyTreeNode* father;
MyTreeNode (char data, int weight) {
this->weight = weight;
this->data = data;
this->isBianLi = false;
this->code = '0';
this->codes = "";
this->isfather = 0;
this->father = NULL;
this->left = NULL;
this->right = NULL;
}
void SetChild (MyTreeNode* left, MyTreeNode* right) {
this->left = left;
this->right = right;
}
void SetFather(int isfather) {
this->isfather = isfather;
}
void SetFather(MyTreeNode* father) {
this->father = father;
}
};
#endif
定义一个类MyTreeNode,
里面有基本的类型data,weigth,isBianLi等。
还有left,rigth,father。他们是指针,是二叉树的左右叉树和父叉树。
还有构造函数MyTreeNode (char data, int weight) 和一些函数;每个类本身都有一个this指针,代表对象本身。
像构造函数的data变量,与类本身的变量data是一样的,为了区分,加this。后面函数雷同。
你是刚开始学数据结构还是C语言?建议你刚开始学先不要研究算法,先把语法搞懂了,不然很吃力,我当初学数据结构的时候C语言基础不好,完全不知道在说什么,现在学了java,再去看见java 语言描述的数据结构就容易多了。