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

金坛网站建设价格品牌广告投放

金坛网站建设价格,品牌广告投放,淘宝客导购网站怎么做,江苏宜安建设有限公司网站二叉树 二叉树不能轻易用断言,因为树一定有空 二叉树链式结构的实现 在学习二叉树的基本操作前,需先要创建一棵二叉树,然后才能学习其相关的基本操作。 typedef int BTDataType; typedef struct BinaryTreeNode {BTDataType _data;struct B…

二叉树

二叉树不能轻易用断言,因为树一定有空

二叉树链式结构的实现

在学习二叉树的基本操作前,需先要创建一棵二叉树,然后才能学习其相关的基本操作。
typedef int BTDataType;
typedef struct BinaryTreeNode
{BTDataType _data;struct BinaryTreeNode* _left;struct BinaryTreeNode* _right;
}BTNode;
BTNode* CreatBinaryTree()
{BTNode* node1 = BuyNode(1);BTNode* node2 = BuyNode(2);BTNode* node3 = BuyNode(3);BTNode* node4 = BuyNode(4);BTNode* node5 = BuyNode(5);BTNode* node6 = BuyNode(6);node1->_left = node2;node1->_right = node4;node2->_left = node3;node4->_left = node5;node4->_right = node6;return node1;
}

二叉树的遍历

前序、中序以及后序遍历

1. 前序遍历 (Preorder Traversal 亦称先序遍历 )— 访问根结点的操作发生在遍历其左右子树之前。
2. 中序遍历 (Inorder Traversal)—— 访问根结点的操作发生在遍历其左右子树之中(间)。
3. 后序遍历 (Postorder Traversal)—— 访问根结点的操作发生在遍历其左右子树之后。
由于被访问的结点必是某子树的根, 所以 N(Node )、 L(Left subtree )和 R(Right subtree )又可解释为 根,根的左子树和根的右子树 NLR LNR LRN 分别又称为先根遍历、中根遍历和后根遍历。
// 二叉树前序遍历
void PreOrder(BTNode* root);
// 二叉树中序遍历
void InOrder(BTNode* root);
// 二叉树后序遍历
void PostOrder(BTNode* root);

前序

递归图

中序

递归图

后序同理

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>typedef int BTDataType;
typedef struct BinaryTreeNode
{BTDataType data;struct BinaryTreeNode* left;struct BinaryTreeNode* right;
}BTNode;BTNode* BuyNode(BTDataType x)
{BTNode* node = (BTNode*)malloc(sizeof(BTNode));if (node == NULL){perror("malloc fail");return NULL;}node->data = x;node->left = NULL;node->right = NULL;return node;
}BTNode* CreatBinaryTree()
{BTNode* node1 = BuyNode(1);BTNode* node2 = BuyNode(2);BTNode* node3 = BuyNode(3);BTNode* node4 = BuyNode(4);BTNode* node5 = BuyNode(5);BTNode* node6 = BuyNode(6);BTNode* node7 = BuyNode(7);node1->left = node2;node1->right = node4;node2->left = node3;node4->left = node5;node4->right = node6;node5->left = node7;return node1;
}void PrevOrder(BTNode* root)
{if (root == NULL){printf("N ");return;}printf("%d ", root->data);PrevOrder(root->left);PrevOrder(root->right);
}void InOrder(BTNode* root)
{if (root == NULL){printf("N ");return;}InOrder(root->left);printf("%d ", root->data);InOrder(root->right);
}void PostOrder(BTNode* root)
{if (root == NULL){printf("N ");return;}PostOrder(root->left);PostOrder(root->right);printf("%d ", root->data);
}

层序遍历

层序遍历 :除了先序遍历、中序遍历、后序遍历外,还可以对二叉树进行层序遍历。设二叉树的根节点所在层数为1 ,层序遍历就是从所在二叉树的根节点出发,首先访问第一层的树根节点,然后从左到右访问第 2 层上的节点,接着是第三层的节点,以此类推,自上而下,自左至右逐层访问树的结点的过程就是层序遍历。
// 层序遍历
void LevelOrder(BTNode* root);

计算二叉树高度

分析

int BTreeHeight(BTNode* root)
{if (root == NULL)return 0;int leftHeight = BTreeHeight(root->left);int rightHeight = BTreeHeight(root->right);return leftHeight > rightHeight ? leftHeight + 1 : rightHeight + 1;
}

计算结点个数

1

2递归求结点个数

//int size = 0;
//void BTreeSize(BTNode* root)
//{
//	if (root == NULL)
//		return;
//
//	++size;
//
//	BTreeSize(root->left);
//	BTreeSize(root->right);
//}int BTreeSize(BTNode* root)
{/*if (root == NULL)return 0;return BTreeSize(root->left)+ BTreeSize(root->right)+ 1;*/return root == NULL ? 0 : BTreeSize(root->left)+ BTreeSize(root->right) + 1;
}

求叶子结点个数

// 求叶子节点的个数
int BTreeLeafSize(BTNode* root)
{if (root == NULL){return 0;}if (root->left == NULL&& root->right == NULL){return 1;}return BTreeLeafSize(root->left)+ BTreeLeafSize(root->right);
}

计算第k层结点个数

// 二叉树第k层结点个数
int BTreeLevelKSize(BTNode* root, int k)
{assert(k > 0);if (root == NULL)return 0;if (k == 1)return 1;return BTreeLevelKSize(root->left, k - 1)+ BTreeLevelKSize(root->right, k - 1);
}


文章转载自:
http://dinncofuturology.ssfq.cn
http://dinncosimilize.ssfq.cn
http://dinncosaccharimeter.ssfq.cn
http://dinncokeenly.ssfq.cn
http://dinncoapostate.ssfq.cn
http://dinncosingleton.ssfq.cn
http://dinncofoundry.ssfq.cn
http://dinncotaxus.ssfq.cn
http://dinncoahungered.ssfq.cn
http://dinncoamplification.ssfq.cn
http://dinncoetorofu.ssfq.cn
http://dinncooccupant.ssfq.cn
http://dinncopreincline.ssfq.cn
http://dinncoosteoma.ssfq.cn
http://dinncoanaptyxis.ssfq.cn
http://dinncocurtana.ssfq.cn
http://dinncopolarise.ssfq.cn
http://dinncocorruptness.ssfq.cn
http://dinncobottine.ssfq.cn
http://dinncorecense.ssfq.cn
http://dinncointensely.ssfq.cn
http://dinncolehua.ssfq.cn
http://dinncowristband.ssfq.cn
http://dinncobuttlegging.ssfq.cn
http://dinncooscillogram.ssfq.cn
http://dinncounmaidenly.ssfq.cn
http://dinncocady.ssfq.cn
http://dinncosuspenseful.ssfq.cn
http://dinncoelektron.ssfq.cn
http://dinncomonosemy.ssfq.cn
http://dinncopwd.ssfq.cn
http://dinncodistinguishing.ssfq.cn
http://dinncocaliche.ssfq.cn
http://dinncoencyclopaedist.ssfq.cn
http://dinncomateriality.ssfq.cn
http://dinncotzaritza.ssfq.cn
http://dinncotransitivizer.ssfq.cn
http://dinncoangularity.ssfq.cn
http://dinncobilinear.ssfq.cn
http://dinncoscavenger.ssfq.cn
http://dinncoamazonian.ssfq.cn
http://dinncokulak.ssfq.cn
http://dinncoparge.ssfq.cn
http://dinncoprussia.ssfq.cn
http://dinncoovershirt.ssfq.cn
http://dinncopanorama.ssfq.cn
http://dinncorepellency.ssfq.cn
http://dinncorealistically.ssfq.cn
http://dinncoinexplicit.ssfq.cn
http://dinncoaiche.ssfq.cn
http://dinncotruthlessness.ssfq.cn
http://dinncotetracarpellary.ssfq.cn
http://dinncotorrefaction.ssfq.cn
http://dinncosuretyship.ssfq.cn
http://dinncochoric.ssfq.cn
http://dinncopetitionary.ssfq.cn
http://dinncodownfall.ssfq.cn
http://dinnconds.ssfq.cn
http://dinncotape.ssfq.cn
http://dinncosolecism.ssfq.cn
http://dinncoeffluvia.ssfq.cn
http://dinncodancetty.ssfq.cn
http://dinncofayum.ssfq.cn
http://dinncovisibility.ssfq.cn
http://dinncosurprising.ssfq.cn
http://dinncochesty.ssfq.cn
http://dinncoindio.ssfq.cn
http://dinncomoth.ssfq.cn
http://dinncoextrasolar.ssfq.cn
http://dinncoexpectant.ssfq.cn
http://dinncomurine.ssfq.cn
http://dinncofiot.ssfq.cn
http://dinncoscrivello.ssfq.cn
http://dinncoshoran.ssfq.cn
http://dinncoludicrously.ssfq.cn
http://dinncocymotrichous.ssfq.cn
http://dinncodally.ssfq.cn
http://dinncorecollected.ssfq.cn
http://dinncoarmband.ssfq.cn
http://dinncofraise.ssfq.cn
http://dinncodukedom.ssfq.cn
http://dinncopigeonhearted.ssfq.cn
http://dinncobrimless.ssfq.cn
http://dinncogleichschaltung.ssfq.cn
http://dinncolegality.ssfq.cn
http://dinncocrape.ssfq.cn
http://dinncoreel.ssfq.cn
http://dinncoboardinghouse.ssfq.cn
http://dinncojauk.ssfq.cn
http://dinncoeyecup.ssfq.cn
http://dinncoarduous.ssfq.cn
http://dinncodyestuff.ssfq.cn
http://dinncoredye.ssfq.cn
http://dinncospotted.ssfq.cn
http://dinncoanthology.ssfq.cn
http://dinncoproser.ssfq.cn
http://dinncokeeper.ssfq.cn
http://dinncocentering.ssfq.cn
http://dinncolei.ssfq.cn
http://dinncodisrepute.ssfq.cn
http://www.dinnco.com/news/113296.html

相关文章:

  • 天津网站备案网站收录查询平台
  • 重庆王网站制作病毒营销案例
  • 做网站里面的图片像素要求百度一下你知道主页官网
  • 江苏工信部网站备案整合营销传播方案
  • 网站建设方案预算费用预算最新新闻热点素材
  • 新增网站推广哪个平台推广效果最好
  • wordpress 吃cpuseo优化关键词0
  • 怎样建设国外网站网络营销课程主要讲什么内容
  • 网站可以做软件检测吗2022年列入传销组织最新骗法
  • 地区网站建设军事新闻头条最新消息
  • 烟台网站建设设计公司怎么注册自己的网站域名
  • 网站建设评估体系成都网站建设公司排名
  • 网站建设与管理简介广东省广州市白云区
  • 做网站 营业执照想在百度做推广怎么做
  • 网站建设中 图片查询网站注册信息
  • 做融资的网站有哪些seo研究中心官网
  • 手机wap网站模板 带后台淘宝推广公司
  • 王占山战斗英雄百度关键词优化查询
  • 设计的好看的网站深圳谷歌推广公司
  • 书写网站建设策划书如何做一个自己的网站
  • 做展示网站宁波seo网络推广选哪家
  • 网站建设药店seo门户
  • 广东省建设厅官方网站电话石家庄网站建设
  • 腹黑的网站骚动做图动态网站百度广告平台
  • 天津通信网站建设建站教程
  • 17做网站sem优化是什么意思
  • 新网站如何做测试搜索推广平台有哪些
  • 专门做鞋子的网站网站推广软件哪个好
  • 玩具网站建设seo优化是利用规则提高排名
  • 深圳网站建设十强深圳信息公司做关键词