二叉树深度的递归算法.docx

上传人:小飞机 文档编号:3232210 上传时间:2023-03-12 格式:DOCX 页数:1 大小:36.30KB
返回 下载 相关 举报
二叉树深度的递归算法.docx_第1页
第1页 / 共1页
亲,该文档总共1页,全部预览完了,如果喜欢就下载吧!
资源描述

《二叉树深度的递归算法.docx》由会员分享,可在线阅读,更多相关《二叉树深度的递归算法.docx(1页珍藏版)》请在三一办公上搜索。

二叉树深度的递归算法/二叉树深度的递归算法 int depth(BTree root) int ldepth,rdepth; if(!root) return 0; else ldepth = depth(root-lchild); rdepth = depth(root-rchild); return ldepthrdepth?ldepth+1;rdepth+1; / 二叉树深度的非递归算法 int depth2(BTree root) int top = 0; int depth = 0,temp = 0; /temp 保存当前单分支的最大值 BTree p = root; BTree nodePointerMAX_TREE_DEGREE; while(p | top 0) if(p) nodePointertop = p; + top; + depth; /统计单分支的深度 p = p-lchild; else - top; p = nodePointertop; p = p-rchild; if(p = NULL) /单分支结束 if(depth temp ) temp = depth; - depth; /else /while return temp;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号