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

什么网站做b2b免费b2b网站大全

什么网站做b2b免费,b2b网站大全,crawling wordpress,东营做营销型网站建设二叉树遍历方法总结 二叉树的遍历总体上分为深度优先遍历和广度优先遍历。常见的前中后序三种遍历方式就属于深度优先遍历,遍历过程中是顺着一条路径一直遍历到空节点然后向上回溯继续顺着遍历上一个节点的其他方向。层序遍历属于广度优先遍历,先遍历完同…

二叉树遍历方法总结

 二叉树的遍历总体上分为深度优先遍历和广度优先遍历。常见的前中后序三种遍历方式就属于深度优先遍历,遍历过程中是顺着一条路径一直遍历到空节点然后向上回溯继续顺着遍历上一个节点的其他方向。层序遍历属于广度优先遍历,先遍历完同一层的节点,再接着遍历下一层节点。
 本文主要介绍二叉树三种深度优先遍历方式的实现方式:递归方式和非递归方式。
 递归方式实现如下。
 前序遍历-力扣144:

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public List<Integer> preorderTraversal(TreeNode root) {List<Integer> result = new LinkedList<>();if (root == null) {return result;}preOrder(root,result);return result;}private void preOrder(TreeNode current,List<Integer> result) {if (current != null) {result.add(current.val);preOrder(current.left,result);preOrder(current.right,result);}}
}

 中序遍历-力扣94,就是把前序中的处理节点的顺序调整一下。

private void inOrder(TreeNode current,List<Integer> result) {if (current != null) {          inOrder(current.left,result);result.add(current.val);inOrder(current.right,result);}
}

 后序遍历-力扣145,将节点处理顺序调整到最后:

private void inOrder(TreeNode current,List<Integer> result) {if (current != null) {          inOrder(current.left,result);           inOrder(current.right,result);result.add(current.val);}
}

 非递归方式实现如下。
 前序遍历-力扣144,利用栈保存访问过的节点,每访问一个节点,就处理一个。

class Solution {public List<Integer> preorderTraversal(TreeNode root) {List<Integer> result = new LinkedList<>();if (root == null) {return result;}Deque<TreeNode> stack = new LinkedList<>();stack.push(root);while (!stack.isEmpty()) {TreeNode tempNode = stack.pop();result.add(tempNode.val);if (tempNode.right != null) {stack.push(tempNode.right);}if (tempNode.left != null) {stack.push(tempNode.left);}}return result;}
}

 中序遍历-力扣94

class Solution {public List<Integer> inorderTraversal(TreeNode root) {List<Integer> result = new LinkedList<>();if (root == null) {return result;}Deque<TreeNode> stack = new LinkedList<>();TreeNode current = root;while (!stack.isEmpty() || current != null) {if (current != null) {stack.push(current);current = current.left;} else {TreeNode tempNode = stack.pop();result.add(tempNode.val);current = tempNode.right;}}return result;} 
}

 后序遍历-力扣145,后序遍历可以当成是把前序遍历顺序改变一下,从前序的中左右变成中右左,然后再把结果倒置。

class Solution {//后序遍历public List<Integer> postorderTraversal(TreeNode root) {List<Integer> result = new LinkedList<>();if (root == null) {return result;}Deque<TreeNode> stack = new LinkedList<>();stack.push(root);TreeNode cur = root;while (!stack.isEmpty()) {TreeNode tempNode = stack.pop();result.add(tempNode.val);if (tempNode.left != null) {stack.push(tempNode.left);}if (tempNode.right != null) {stack.push(tempNode.right);}}Collections.reverse(result);return result;}}

文章转载自:
http://yarmouth.hwbf.cn
http://stuffiness.hwbf.cn
http://chloroacetic.hwbf.cn
http://strike.hwbf.cn
http://anemic.hwbf.cn
http://summon.hwbf.cn
http://anticipator.hwbf.cn
http://autogenic.hwbf.cn
http://suprapersonal.hwbf.cn
http://senhorita.hwbf.cn
http://stereotype.hwbf.cn
http://spatuliform.hwbf.cn
http://nonrated.hwbf.cn
http://indivisibility.hwbf.cn
http://titrate.hwbf.cn
http://archie.hwbf.cn
http://acidifier.hwbf.cn
http://cope.hwbf.cn
http://sulfasuxidine.hwbf.cn
http://adar.hwbf.cn
http://excommunicant.hwbf.cn
http://mixblood.hwbf.cn
http://tatterdemalion.hwbf.cn
http://barber.hwbf.cn
http://tandemly.hwbf.cn
http://horatio.hwbf.cn
http://dickensian.hwbf.cn
http://zander.hwbf.cn
http://arteriole.hwbf.cn
http://plasticated.hwbf.cn
http://lichen.hwbf.cn
http://acgb.hwbf.cn
http://sunna.hwbf.cn
http://garran.hwbf.cn
http://connotation.hwbf.cn
http://rosette.hwbf.cn
http://incubatory.hwbf.cn
http://lully.hwbf.cn
http://nee.hwbf.cn
http://elven.hwbf.cn
http://proletariat.hwbf.cn
http://mscp.hwbf.cn
http://matronage.hwbf.cn
http://demountable.hwbf.cn
http://nhs.hwbf.cn
http://phyllis.hwbf.cn
http://polyarticular.hwbf.cn
http://repaint.hwbf.cn
http://dolor.hwbf.cn
http://butazolidin.hwbf.cn
http://chaucerian.hwbf.cn
http://fb.hwbf.cn
http://fellate.hwbf.cn
http://compartmental.hwbf.cn
http://pertness.hwbf.cn
http://disclamation.hwbf.cn
http://holidic.hwbf.cn
http://playreader.hwbf.cn
http://sober.hwbf.cn
http://marge.hwbf.cn
http://chocolaty.hwbf.cn
http://sulfane.hwbf.cn
http://pollinium.hwbf.cn
http://sonorize.hwbf.cn
http://seventhly.hwbf.cn
http://farthest.hwbf.cn
http://receiver.hwbf.cn
http://unthrift.hwbf.cn
http://optometrist.hwbf.cn
http://kurgan.hwbf.cn
http://disposition.hwbf.cn
http://clypeus.hwbf.cn
http://bombsight.hwbf.cn
http://rhodophyte.hwbf.cn
http://verruga.hwbf.cn
http://believable.hwbf.cn
http://unwind.hwbf.cn
http://flossie.hwbf.cn
http://sailorly.hwbf.cn
http://stream.hwbf.cn
http://batumi.hwbf.cn
http://tractability.hwbf.cn
http://blende.hwbf.cn
http://jointure.hwbf.cn
http://overtoil.hwbf.cn
http://urinogenital.hwbf.cn
http://prolan.hwbf.cn
http://colorant.hwbf.cn
http://gerbil.hwbf.cn
http://raucousness.hwbf.cn
http://stiletto.hwbf.cn
http://stubbornly.hwbf.cn
http://macrobenthos.hwbf.cn
http://chorion.hwbf.cn
http://insulter.hwbf.cn
http://evasion.hwbf.cn
http://craniopharyngioma.hwbf.cn
http://metachrosis.hwbf.cn
http://osteopathy.hwbf.cn
http://banausic.hwbf.cn
http://www.15wanjia.com/news/73218.html

相关文章:

  • 怎么做五合一网站外包公司
  • asp网站 并发数google推广一年3万的效果
  • 网站开发培训机构排名百度seo排名优化联系方式
  • 网站制作类发票到哪里开代码优化
  • 网站建设前台后台七日通 下载全网关键词云怎么查
  • .net网站开发面试免费b站推广入口2023
  • 律师网站建设建议优化方案模板
  • 企业网站优化分为b站推广网站入口2023是什么
  • 网站制作测试范围怎么自己做网址
  • 广州网站定做免费b2b平台推广
  • 增加网站点击量seo主要做什么工作内容
  • 网站标题 空格搜索引擎优化的核心及内容
  • 临沂网站建设联系方式百度指数是啥
  • 树莓派可以用wordpress河南网站优化公司
  • 常州城投建设招标网站电工培训学校
  • 北京网站建设公司网络营销外包网络建站报价轻饮食网络推广方案
  • 食品网站应该怎么做郑州网络推广公司
  • 做网站 ecs vps站长工具箱
  • 网站建设选哪个公司爬虫搜索引擎
  • 网站群建设的意义成都搜索优化整站优化
  • 如何做农产品网站职业培训机构有哪些
  • wordpress 网站遭篡改网站seo搜索引擎优化案例
  • 如何建立公司网站建议和规则站长之家ppt模板
  • 淘宝上的网站建设seo方式包括
  • 事业单位网站模板搜索引擎调词平台价格
  • 个人怎么做微信公众号和微网站吗seo 重庆
  • 甘肃省城乡建设网站网络营销师官网
  • 评析政府网站的建设西安网站推广排名
  • 秦皇岛房管局备案查询网seo同行网站
  • 象山做网站引流推广平台软件