求二叉树宽度和深度
来源:互联网 发布:移动办公软件技术指标 编辑:程序博客网 时间:2024/06/05 09:37
//二叉树宽度
int widthOfBinaryTree(Node *root)
{if(root == NULL)
return 0;
queue<Node*> nodeQueue;
int maxWidth = i;
nodeQueue.push(root);
while(true)
{
int length = nodeQueue.size();
if (length == 0)
btreak;
while (length > 0)
{
Node* temp = nodeQueue.front();
nodeQueue.pop();
length--;
if (temp->left);
nodeQueue.push(node->left);
if (temp->right)
nodeQueue.push(node->right);
}
maxWidth = maxWidth > nodeQueue.size() ? maxWidth : nodeQueue.size();
}
return maxWidth;
}
//二叉树深度
int depthOfBineryTree(Node* root){
if (root == NULL)
return 0;
int left = depthOfBineryTree(root->left);
int right = depthOfBineryTree(root->right);
return (left > right ? left+1 : right+1);
}
阅读全文
0 0
- 求二叉树的深度和宽度
- 求二叉树的深度和宽度
- 求二叉树的深度和宽度
- 求二叉树的深度和宽度
- 求二叉树的深度和宽度
- 求二叉树的深度和宽度
- 求二叉树的深度和宽度
- 求二叉树的深度和宽度
- 求二叉树宽度和深度
- 华为练习 求二叉树的宽度和深度
- 求二叉树的深度和宽度[Java]
- 求二叉树的深度和宽度平衡最大距离
- 求二叉树的深度、宽度和叶子结点数
- 华为oj 求二叉树的深度和宽度
- 求二叉树的深度和宽度[Java]
- 求二叉树的深度和宽度[Java]
- 求二叉数的深度和宽度
- 求二叉数的深度和宽度
- 对类库作修改后,web应用程序如何获取改变后的类库
- Tensorflow学习笔记
- 64位ubuntu运行32位程序的方法
- pep8规范-常见错误 python-vscode
- arcgis for javascript 判断点在面内
- 求二叉树宽度和深度
- 2017ICPC青岛网络赛 Brute Force Sorting
- RabbitMQ系列—RabbitMQ 安装
- QGC地图上任务项
- 洛谷3370字符串哈希模板
- void ( *p ) (void) 和 void ( *p () ) (void)的区别
- android apk下载DownloadDialog
- 微信红包后台系统可用性设计实践
- linux下查看已经安装的jdk 并卸载jdk的方法