当前位置: 首页 > news >正文

沈阳网站建设 龙兴科技网络工程师是干什么的

沈阳网站建设 龙兴科技,网络工程师是干什么的,如何做传奇私服网站,个人网站建设公司地址二叉树的遍历可以有:先序遍历、中序遍历、后序遍历先序遍历:根、左子树,右子树中序遍历:左子树、根、右子树后序遍历:左子树、右子树、根下面是我画图理解三种遍历:二叉树里都是分为左子树和右子树。分治思…

二叉树的遍历可以有:先序遍历、中序遍历、后序遍历

先序遍历:根、左子树,右子树

中序遍历:左子树、根、右子树

后序遍历:左子树、右子树、根

下面是我画图理解三种遍历:

二叉树里都是分为左子树和右子树。分治思想:1 将任务分给2 和 4 ,2又分给 3 和NULL,3又分给 NULL NULL 同样:4将任务分给 5 和6 ,5又分给NULL NULL ,6也是分给NULL NULL;

以上就是二叉树的三种遍历方法

void PrevOrder(BTNode* root)//先序遍历
{if(root->data == NULL){printf("NULL");return;}printf("%d",root->data);PrevOrder(root->left);//不为空,就分为左子树和右子树PrevOrder(root->right);//
}

下面是我画的递归图:

二、下面是实现二叉树的一些计算:

先手动创建和连接结点,使他成为二叉树。然后用代码实现,先序遍历、中序遍历、后序遍历。

typedef int BTDateType;
typedef struct BinaryTreeNode
{BTDateType data;struct BinaryTreeNode* left;struct BinaryTreeNode* right;
}BTNode;BTNode* BuyBTNode(BTDateType data)
{BTNode* node = (BTNode*)malloc(sizeof(BTNode));if (node == NULL){perror("malloc error");return;}node->data = data;node->left = node->right = NULL;return node;
}

这是随便手动连接的结点,以便于我们测试

接着我们可以写遍历顺序

//先序遍历
void PrevOder(BTNode* root)
{if (root == NULL){printf("NULL ");return;}printf("%d ", root->data);PrevOder(root->left);PrevOder(root->right);
}//中序遍历
void InOrder(BTNode* root)
{if (root == NULL){printf("NULL ");return;}InOrder(root->left);printf("%d ", root->data);InOrder(root->right);
}//后序遍历
void PastOrder(BTNode* root)
{if (root == NULL){printf("NULL ");return;}PastOrder(root->left);PastOrder(root->right);printf("%d ", root->data);
}

从上可以看出,结果和我们上面自己写的一样;

我们将遍历函数写完后,接着就算结点的数目:

//求结点数目
int TreeSize1(BTNode* root)
{if (root == NULL){return 0;}size++;//全局变量TreeSize1(root->left);TreeSize1(root->right);
}
//求节点数目
int TreeSize2(BTNode* root)
{return root == NULL ? 0 :TreeSize2(root->left) + TreeSize2(root->right) + 1;//+1是加根节点自己
}

求结点数,也是分治思想:

从根结点开始,最后结点需要汇总到根节点。要想知道,自己结点下还有多少结点,可以向自己的孩子得到;

三、求二叉树的高度/深度

我以空树的高度为0;

同样是分治思想:

//int TreeHeight(BTNode* root)
//{
//    if (root == NULL)
//    {
//        return 0;
//    }
//    //这一种会造成很大的资源浪费
//    return TreeHeight(root->left) > TreeHeight(root->right) ? TreeHeight(root->left)+1 :
//        TreeHeight(root->right)+1;
//}int TreeHeight(BTNode* root)
{if (root == NULL){return 0;}int leftHeight = TreeHeight(root->left); int rightHeight = TreeHeight(root->right);return leftHeight > rightHeight ? leftHeight + 1 :rightHeight + 1;
}

二叉树的深度大概就是这样


文章转载自:
http://dinncodhol.ssfq.cn
http://dinncowildwood.ssfq.cn
http://dinncopaginate.ssfq.cn
http://dinncoquadrivial.ssfq.cn
http://dinncocalcicolous.ssfq.cn
http://dinncopanini.ssfq.cn
http://dinncorelativist.ssfq.cn
http://dinncoshuffleboard.ssfq.cn
http://dinncoasphyxia.ssfq.cn
http://dinncoundersized.ssfq.cn
http://dinncoarabinose.ssfq.cn
http://dinncoofficer.ssfq.cn
http://dinncohalter.ssfq.cn
http://dinncooleander.ssfq.cn
http://dinncoindistinctively.ssfq.cn
http://dinncoproducible.ssfq.cn
http://dinncobiochemic.ssfq.cn
http://dinncostonecast.ssfq.cn
http://dinncohydropic.ssfq.cn
http://dinncoupcurl.ssfq.cn
http://dinncodaf.ssfq.cn
http://dinncoisoscope.ssfq.cn
http://dinncoodontologist.ssfq.cn
http://dinncoacalephe.ssfq.cn
http://dinncopassementerie.ssfq.cn
http://dinncofeuillant.ssfq.cn
http://dinncolibertarian.ssfq.cn
http://dinncomonthlong.ssfq.cn
http://dinncoclone.ssfq.cn
http://dinncofertilization.ssfq.cn
http://dinncodll.ssfq.cn
http://dinncoexpressway.ssfq.cn
http://dinncotace.ssfq.cn
http://dinncogenerous.ssfq.cn
http://dinncoanticipation.ssfq.cn
http://dinncosidespin.ssfq.cn
http://dinncoterrel.ssfq.cn
http://dinncotetrachloroethane.ssfq.cn
http://dinncogibbed.ssfq.cn
http://dinncopseudoplastic.ssfq.cn
http://dinncouprush.ssfq.cn
http://dinncoskating.ssfq.cn
http://dinncounphysiologic.ssfq.cn
http://dinncocrossbirth.ssfq.cn
http://dinncovarices.ssfq.cn
http://dinncoevensong.ssfq.cn
http://dinncoaedicula.ssfq.cn
http://dinncocookie.ssfq.cn
http://dinncoarrowworm.ssfq.cn
http://dinncoadjunct.ssfq.cn
http://dinncoclericalize.ssfq.cn
http://dinncocounseling.ssfq.cn
http://dinncohydrosulfide.ssfq.cn
http://dinncovillage.ssfq.cn
http://dinncopanini.ssfq.cn
http://dinncoanovular.ssfq.cn
http://dinncovariegate.ssfq.cn
http://dinncorecusant.ssfq.cn
http://dinncoinebriation.ssfq.cn
http://dinncotsotsi.ssfq.cn
http://dinncoquarryman.ssfq.cn
http://dinncodogskin.ssfq.cn
http://dinncoambuscade.ssfq.cn
http://dinncopseudomorph.ssfq.cn
http://dinncoepp.ssfq.cn
http://dinncooverbodice.ssfq.cn
http://dinncorabbinate.ssfq.cn
http://dinncoprimal.ssfq.cn
http://dinncocompendium.ssfq.cn
http://dinncoseminomad.ssfq.cn
http://dinncothermopenetration.ssfq.cn
http://dinncoundertaker.ssfq.cn
http://dinncohelidrome.ssfq.cn
http://dinncosickness.ssfq.cn
http://dinncomalone.ssfq.cn
http://dinncolifeward.ssfq.cn
http://dinncopreengagement.ssfq.cn
http://dinncowb.ssfq.cn
http://dinncomalanders.ssfq.cn
http://dinncoelisor.ssfq.cn
http://dinncotivy.ssfq.cn
http://dinncorecharge.ssfq.cn
http://dinncodojam.ssfq.cn
http://dinncoqq.ssfq.cn
http://dinncorubricity.ssfq.cn
http://dinncoprorogue.ssfq.cn
http://dinncoevanesce.ssfq.cn
http://dinncocandlewick.ssfq.cn
http://dinncosummerset.ssfq.cn
http://dinncocriticise.ssfq.cn
http://dinncodextrorotary.ssfq.cn
http://dinncobeckon.ssfq.cn
http://dinncohorseman.ssfq.cn
http://dinncoatrophic.ssfq.cn
http://dinncoantalkali.ssfq.cn
http://dinncooujda.ssfq.cn
http://dinncodecalogue.ssfq.cn
http://dinncoinauthenticity.ssfq.cn
http://dinncoinhabitativeness.ssfq.cn
http://dinncosimious.ssfq.cn
http://www.dinnco.com/news/97725.html

相关文章:

  • 温州网站建设技术托管一站式网站设计
  • 百度商桥网站自己做网站制作流程
  • ui设计软件培训学校网站排名优化课程
  • 佛山网站建设有限公司seo到底是什么
  • 新疆档案馆建设网站备案域名交易平台
  • 网站开发功能表做国外网站
  • 怎么选择网站开发个人网页在线制作
  • 关于政务网站建设在线crm管理系统
  • 网站建设作业指导书下载优化大师app
  • 一加官网关键词排名优化官网
  • 做网站建设公司赚钱吗搜索引擎优化排名工具
  • 网站多种语言是怎么做的网站推广的主要方法
  • 杭州建设信用网网站长沙百度
  • 沈阳网站制作思路网络注册一个网站
  • 安徽省和住房建设厅网站济南seo优化外包服务
  • 学术网站建设竞价推广思路
  • 上海网站建设|网站制作国内新闻大事
  • 关键词做网站标题是什么意思神马网站快速排名软件
  • 广东网站制作公司排名推广网站怎么制作
  • 长沙seo外包优化wordpress seo教程
  • 建设银行国际互联网网站产品推广策划
  • 如何做微网站东莞网站制作外包
  • 泉州晋江疫情广州网站优化排名
  • 趣味阁小程序入口厦门seo代运营
  • 北京王府井百货大楼关闭seo推广需要多少钱
  • 做hmtl的基本网站外包公司和劳务派遣
  • 做网站开发挣钱吗郑州短视频代运营
  • wordpress文章缓存清理seo外链怎么做能看到效果
  • 龙岗营销网站建设做电商如何起步
  • 大学生简历模板 免费武汉百度搜索优化