Forest.h
资源名称:7.rar [点击查看]
上传用户:lsjld999
上传日期:2022-06-19
资源大小:980k
文件大小:1k
源码类别:

图形图象

开发平台:

Visual C++

  1. #include "iostream"
  2. using namespace std;
  3. struct fnode 
  4. {
  5. int data;
  6. fnode *firstson;
  7. fnode *nextbrother;
  8. fnode(){};
  9. fnode(int a,fnode *f,fnode *n)
  10. {
  11. data=a; firstson=f;
  12. nextbrother=n;
  13. };
  14. };
  15. class  Forest
  16. {
  17. public :
  18. fnode *root;
  19. Forest();//构造函数
  20. int height();//求森林的高度
  21. private:
  22. int height(fnode * p );
  23. queue<fnode *> Q;
  24. };
  25. Forest::Forest()
  26. {
  27. root=NULL;  
  28. }
  29. int Forest::height(fnode *p)
  30. { int i;
  31. if (p==NULL) return 0;
  32. else {
  33. i=(1+height(p->firstson))>height(p->nextbrother)?(1+height(p->firstson)):height(p->nextbrother);
  34. return i;
  35. }
  36. }
  37. int Forest::height()
  38. {
  39.  return height(root);
  40. }