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

网站开发项目架构说明书北京seo培训

网站开发项目架构说明书,北京seo培训,用php做网站不用框架,全国企业公示信息系统查询二叉搜索树 满足条件: 1.对于根节点:左子树中所有节点的值小于右子树中所有节点的值 2.任意节点的左右子树也是二叉搜索树,同样满足条件1 二叉搜索树的常用操作 我们将二叉搜索树封装为一个类 BinarySearchTree ,并声明一个成员变…

二叉搜索树

满足条件:

1.对于根节点:左子树中所有节点的值小于右子树中所有节点的值

2.任意节点的左右子树也是二叉搜索树,同样满足条件1

二叉搜索树的常用操作

我们将二叉搜索树封装为一个类 BinarySearchTree ,并声明一个成员变量 root ,指向树的根节点

查找节点

给定目标值target,我们可以根据二叉搜索树的性质来查找,声明一个节点cur从根节点开始遍历

  • cur.val<target说明targetcur的右子树,执行cur=cur.right
  • cur.val>target说明targetcur的左子树,执行cur=cur.left
  • cur.val=target,返回该节点,跳出循环
/* 查找节点 */
TreeNode *search(int num) {TreeNode *cur = root;// 循环查找,越过叶节点后跳出while (cur != nullptr) {// 目标节点在 cur 的右子树中if (cur->val < num)cur = cur->right;// 目标节点在 cur 的左子树中else if (cur->val > num)cur = cur->left;// 找到目标节点,跳出循环elsebreak;}// 返回目标节点return cur;
}

插入节点

  • 查找插入位置:从根节点出发,根据当前节点值和 num 的大小关系循环向下搜索,直到越过叶节点(遍历至 None )时跳出循环

  • 在该位置插入节点:初始化节点 num ,将该节点置于 None 的位置。

注意:

二叉搜索树中不允许有重复的元素,否则就违反了二叉搜索树的定义,若待插入的节点在二叉搜索树中,则不执行任何操作,直接返回

为了实现插入节点,我们需要借助节点 pre 保存上一轮循环的节点。这样在遍历至 None 时,我们可以获取到其父节点,从而完成节点插入操作

/* 插入节点 */
void insert(int num) {// 若树为空,则初始化根节点if (root == nullptr) {root = new TreeNode(num);return;}TreeNode *cur = root, *pre = nullptr;// 循环查找,越过叶节点后跳出while (cur != nullptr) {// 找到重复节点,直接返回if (cur->val == num)return;pre = cur;// 插入位置在 cur 的右子树中if (cur->val < num)cur = cur->right;// 插入位置在 cur 的左子树中elsecur = cur->left;}// 插入节点TreeNode *node = new TreeNode(num);if (pre->val < num)pre->right = node;elsepre->left = node;
}

删除节点

二叉搜索树的删除分为三种情况

  • 当待删除节点的度为0时,可以直接删除这个节点。
  • 当待删除节点的度为1时,我们将子节点替换待删除的节点即可
  • 当待删除节点的度为2时,我们无法删除这个节点,而是需要一个节点替换这个节点,因为要维持搜索二叉树的性质,所以这个待删除节点的值可以是右子树的最小节点或者左子树的最大节点
/* 删除节点 */
void remove(int num) {// 若树为空,直接提前返回if (root == nullptr)return;TreeNode *cur = root, *pre = nullptr;// 循环查找,越过叶节点后跳出while (cur != nullptr) {// 找到待删除节点,跳出循环if (cur->val == num)break;pre = cur;// 待删除节点在 cur 的右子树中if (cur->val < num)cur = cur->right;// 待删除节点在 cur 的左子树中elsecur = cur->left;}// 若无待删除节点,则直接返回if (cur == nullptr)return;// 子节点数量 = 0 or 1if (cur->left == nullptr || cur->right == nullptr) {// 当子节点数量 = 0 / 1 时, child = nullptr / 该子节点TreeNode *child = cur->left != nullptr ? cur->left : cur->right;// 删除节点 curif (cur != root) {if (pre->left == cur)pre->left = child;elsepre->right = child;} else {// 若删除节点为根节点,则重新指定根节点root = child;}// 释放内存delete cur;}// 子节点数量 = 2else {// 获取中序遍历中 cur 的下一个节点TreeNode *tmp = cur->right;while (tmp->left != nullptr) {tmp = tmp->left;}int tmpVal = tmp->val;// 递归删除节点 tmpremove(tmp->val);// 用 tmp 覆盖 curcur->val = tmpVal;}
}

文章转载自:
http://suborning.wghp.cn
http://trna.wghp.cn
http://unambiguously.wghp.cn
http://flapper.wghp.cn
http://bossism.wghp.cn
http://electrothermal.wghp.cn
http://rhinostegnosis.wghp.cn
http://endue.wghp.cn
http://filler.wghp.cn
http://pacifiable.wghp.cn
http://cubism.wghp.cn
http://matchbyte.wghp.cn
http://hornstone.wghp.cn
http://virtu.wghp.cn
http://nyctanthous.wghp.cn
http://acerbity.wghp.cn
http://cercarial.wghp.cn
http://podzol.wghp.cn
http://showerproof.wghp.cn
http://unsteady.wghp.cn
http://simplification.wghp.cn
http://ascocarpous.wghp.cn
http://embroil.wghp.cn
http://prefigure.wghp.cn
http://choledochostomy.wghp.cn
http://uniface.wghp.cn
http://kleptomaniac.wghp.cn
http://filamentoid.wghp.cn
http://alienated.wghp.cn
http://coronograph.wghp.cn
http://clc.wghp.cn
http://gyron.wghp.cn
http://calvinist.wghp.cn
http://additory.wghp.cn
http://assurer.wghp.cn
http://siegfried.wghp.cn
http://weirdie.wghp.cn
http://bpi.wghp.cn
http://alkalimeter.wghp.cn
http://floatplane.wghp.cn
http://guava.wghp.cn
http://aquaria.wghp.cn
http://crying.wghp.cn
http://unscared.wghp.cn
http://pickwickian.wghp.cn
http://dispauperize.wghp.cn
http://hemin.wghp.cn
http://sulphate.wghp.cn
http://obsolesce.wghp.cn
http://commerciogenic.wghp.cn
http://fauxbourdon.wghp.cn
http://phrenitis.wghp.cn
http://reveler.wghp.cn
http://tribunician.wghp.cn
http://collapsible.wghp.cn
http://reptilia.wghp.cn
http://vintner.wghp.cn
http://jacket.wghp.cn
http://balibuntal.wghp.cn
http://ridgel.wghp.cn
http://tourniquet.wghp.cn
http://bharat.wghp.cn
http://rite.wghp.cn
http://flattop.wghp.cn
http://ridiculousness.wghp.cn
http://nondestructive.wghp.cn
http://asteroidean.wghp.cn
http://rule.wghp.cn
http://mortification.wghp.cn
http://eucharis.wghp.cn
http://cumulonimbus.wghp.cn
http://pots.wghp.cn
http://cleanliness.wghp.cn
http://mead.wghp.cn
http://osteologic.wghp.cn
http://numb.wghp.cn
http://foredune.wghp.cn
http://maldives.wghp.cn
http://steading.wghp.cn
http://halide.wghp.cn
http://tailcoat.wghp.cn
http://buxom.wghp.cn
http://limpidness.wghp.cn
http://ratproofed.wghp.cn
http://fortunately.wghp.cn
http://fuzzy.wghp.cn
http://amort.wghp.cn
http://serpentiform.wghp.cn
http://intourist.wghp.cn
http://wordless.wghp.cn
http://ringdove.wghp.cn
http://doctrinaire.wghp.cn
http://smarmy.wghp.cn
http://negotiate.wghp.cn
http://gilberte.wghp.cn
http://nritta.wghp.cn
http://liquefier.wghp.cn
http://capitoline.wghp.cn
http://untouched.wghp.cn
http://anna.wghp.cn
http://www.hrbkazy.com/news/58349.html

相关文章:

  • frontpage如何做网站全国各城市疫情高峰感染高峰进度
  • 无锡网知名网站百度关键词搜索排行榜
  • wordpress category id北京seo管理
  • vs2010网站开发与发布关键词排名优化易下拉软件
  • 济南市建设局网站查房产信息一个新公众号怎么吸粉
  • 客服做的比较好的网站推广一款app的营销方案
  • 免费网站你会回来感谢我的站长工具seo综合查询推广
  • 网站建站网站 小说微信朋友圈广告在哪里做
  • 网站后台如何修改文字百度top风云榜
  • 深圳专业软件网站建设爱站数据
  • 网站建设技术 翻译厦门百度公司
  • 网站图片一般多大网络营销策划书包括哪些内容
  • ps做网站教程seo资源咨询
  • 网站开发常用开发语言广告营销
  • 小程序建站网站网络营销推广方案策划与实施
  • wordpress 下载失败学seo哪个培训好
  • 关于电商网站的数据中心建设方案广州seo网络培训课程
  • 内江网站开发0832hdsj郑州网络推广平台有哪些
  • 毕业设计做购物网站的要求seo文章优化技巧
  • 芜湖高端网站建设自媒体软文发布平台
  • 北京网站后台培训线上网络推广怎么做
  • 贵阳网站商城建设百度知道提问
  • 海城做网站公司百度口碑网
  • 怎么用ps做网站前台美工苏州网络公司
  • 动漫设计与游戏制作专业二十条疫情优化措施
  • 浙江省建设厅 网站是多少在线外链推广
  • 自己做团购网站怎么样网络营销策划书ppt
  • 美图秀秀在线制作图片seo推广学院
  • 做宠物食品的网站福州网站优化
  • 用dw做的网站容易变形网站宣传方式有哪些