Forest.h
资源名称:7.rar [点击查看]
上传用户:lsjld999
上传日期:2022-06-19
资源大小:980k
文件大小:1k
源码类别:
图形图象
开发平台:
Visual C++
- #include "iostream"
- using namespace std;
- struct fnode
- {
- int data;
- fnode *firstson;
- fnode *nextbrother;
- fnode(){};
- fnode(int a,fnode *f,fnode *n)
- {
- data=a; firstson=f;
- nextbrother=n;
- };
- };
- class Forest
- {
- public :
- fnode *root;
- Forest();//构造函数
- int height();//求森林的高度
- private:
- int height(fnode * p );
- queue<fnode *> Q;
- };
- Forest::Forest()
- {
- root=NULL;
- }
- int Forest::height(fnode *p)
- { int i;
- if (p==NULL) return 0;
- else {
- i=(1+height(p->firstson))>height(p->nextbrother)?(1+height(p->firstson)):height(p->nextbrother);
- return i;
- }
- }
- int Forest::height()
- {
- return height(root);
- }
English
