树的基本运用二
来源:互联网 发布:怎么购买已备案域名 编辑:程序博客网 时间:2024/05/05 08:56
树的层次遍历:也即是从跟节点开始,每一层都从左到右输出。可利用队列的先进先出来
void Level_Traverse(Bintree root){queue<Bintree>q;Bintree temp;temp=root;if(temp==NULL)return;q.push (temp);cout<<temp->data;while(!q.empty ()){temp=q.front ();q.pop ();cout<<temp->data<<endl;if(temp->lchild){cout<<temp->lchild<<endl;q.push (temp->lchild);}if(temp->rchild){cout<<temp->rchild<<endl;q.push (temp->rchild);}}}
求树的深度:
int Depth_Bintree(Bintree *root){if(!root)return 0;int len1,len2;len1=Depth_Bintree(root->lchild);len2=Depth_Bintree(root->rchild);return (len1>len2?len1:len2)+1;}
求树的节点个数:利用递归即可实现
int Count_Bintree(Bintree root){if(root){ return ((Count_Bintree(root->lchild)+Count_Bintree(root->rchild))+1);}}
0 0
- 树的基本运用二
- 树的基本运用一
- adb的基本运用
- JPA的基本运用
- service的基本运用
- 二.memcached的运用
- 一些基本的 SQL 运用
- 枚举的基本运用方法
- Game-图的基本运用
- 基本语句的综合运用
- asp.net的基本运用
- sublime text3 的基本运用
- Java线程的基本运用
- 树状数组的基本运用
- myeclipse servlet的基本运用
- 自定义view的基本运用
- 策略模式的基本运用
- 观察者模式的基本运用
- maven入门教程
- Unity5中的高性能物理组件
- java中File目录管理(四)目录管理小工具的设计
- java 动态代理
- gzip和gunzip 解压参数
- 树的基本运用二
- C++中头文件的现状
- 《Java程序设计》第16周周四:GUI编程及文件对话框的使用(项目1)
- 10.11 Beta 2 上不能运行xcode6.3.2了
- mysql 索引
- LeetCode_49---Anagrams
- opencv各种滤波分析bilateralFilter、Laplacian、bitwise_and和GaussianBlur
- Android Application Fundamentals——Android应用程序基础知识
- 数据统计存储过程规范(mysql)