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

html怎么做网站版块百度云盘登录电脑版

html怎么做网站版块,百度云盘登录电脑版,广州做创客教室的厂家网站,公司建网站多少钱文章目录 二叉树递归遍历解题思路代码总结 二叉树的迭代遍历解题思路代码总结 二叉树的统一迭代法解题思路代码总结 草稿图网站 java的Deque 二叉树递归遍历 题目: 144.二叉树的前序遍历 94.二叉树的中序遍历 145.二叉树的后序遍历 解析:代码随想录解析…

文章目录

    • 二叉树递归遍历
      • 解题思路
      • 代码
      • 总结
    • 二叉树的迭代遍历
      • 解题思路
      • 代码
      • 总结
    • 二叉树的统一迭代法
      • 解题思路
      • 代码
      • 总结

草稿图网站
java的Deque

二叉树递归遍历

题目:
144.二叉树的前序遍历
94.二叉树的中序遍历
145.二叉树的后序遍历
解析:代码随想录解析

解题思路

递归遍历
前序:NLR
中序:LNR
后序:LRN

代码

/*** 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> res = new ArrayList<Integer>();preorder(root, res);return res;}public void preorder(TreeNode root, List<Integer> res){if (root == null)return;res.add(root.val);preorder(root.left, res);preorder(root.right, res);}
}//中序
class Solution {public List<Integer> inorderTraversal(TreeNode root) {List<Integer> res = new ArrayList<Integer>();inorder(root, res);return res;}public void inorder(TreeNode root, List<Integer> res){if (root == null)return;inorder(root.left, res);res.add(root.val);inorder(root.right, res);}
}
//后序
class Solution {public List<Integer> postorderTraversal(TreeNode root) {List<Integer> res = new ArrayList<Integer>();postorder(root, res);return res;}public void postorder(TreeNode root, List<Integer> res){if (root == null)return;postorder(root.left, res);postorder(root.right, res);res.add(root.val);}
}

总结

暂无

二叉树的迭代遍历

题目:
144.二叉树的前序遍历
94.二叉树的中序遍历
145.二叉树的后序遍历
解析:代码随想录解析

解题思路

前序:利用一个栈,每次出栈并入栈。
中序:利用一个栈,cur指向root节点,一直走左子树并入栈到空;cur为空时输出栈顶的val,然后使cur指向出栈节点右子树,重复上述步骤。
后序:LRN反过来是NRL,也就是前序换一下,最后倒转一下。

代码

/*** 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> res = new ArrayList<Integer>();if (root == null)return res;Stack<TreeNode> stack = new Stack<TreeNode>();stack.push(root);while(!stack.isEmpty()){TreeNode tmp = stack.pop();res.add(tmp.val);if (tmp.right != null)stack.push(tmp.right);if (tmp.left != null)stack.push(tmp.left);}return res;}
}//中序
class Solution {public List<Integer> inorderTraversal(TreeNode root) {List<Integer> res = new ArrayList<Integer>();if (root == null)return res;Stack<TreeNode> stack = new Stack<TreeNode>();TreeNode cur = root;while (!stack.isEmpty() || cur != null){if (cur != null){stack.push(cur);cur = cur.left;}else{cur = stack.pop();res.add(cur.val);cur = cur.right;}}return res;}
}//后序
class Solution {public List<Integer> postorderTraversal(TreeNode root) {List<Integer> res = new ArrayList<Integer>();if (root == null)return res;Stack<TreeNode> stack = new Stack<TreeNode>();stack.push(root);while(!stack.isEmpty()){TreeNode tmp = stack.pop();res.add(tmp.val);if (tmp.left != null)stack.push(tmp.left);if (tmp.right != null)stack.push(tmp.right);}Collections.reverse(res);return res;}
}

总结

死去的408记忆在攻击我

二叉树的统一迭代法

题目:
144.二叉树的前序遍历
94.二叉树的中序遍历
145.二叉树的后序遍历
解析:代码随想录解析

解题思路

代码结构和递归遍历相似。下面是模拟步骤图
前序
在这里插入图片描述

中序
在这里插入图片描述

后序:
在这里插入图片描述

代码

/*** 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> res = new ArrayList<Integer>();if (root == null)return res;Stack<TreeNode> stack = new Stack<TreeNode>();stack.push(root);while(!stack.isEmpty()){TreeNode node = stack.peek();if (node != null){stack.pop();if (node.right != null) stack.push(node.right);if (node.left != null)  stack.push(node.left);stack.push(node);stack.push(null);    }else{stack.pop();node = stack.pop();res.add(node.val);}}return res;}
}//中序
class Solution {public List<Integer> inorderTraversal(TreeNode root) {List<Integer> res = new ArrayList<Integer>();if (root == null)return res;Stack<TreeNode> stack = new Stack<TreeNode>();stack.push(root);while(!stack.isEmpty()){TreeNode node = stack.peek();if (node != null){stack.pop();if (node.right != null) stack.push(node.right);stack.push(node);stack.push(null); if (node.left != null)  stack.push(node.left);}else{stack.pop();node = stack.pop();res.add(node.val);}}return res;}
}//后序
class Solution {public List<Integer> postorderTraversal(TreeNode root) {List<Integer> res = new ArrayList<Integer>();if (root == null)return res;Stack<TreeNode> stack = new Stack<TreeNode>();stack.push(root);while(!stack.isEmpty()){TreeNode node = stack.peek();if (node != null){stack.pop();stack.push(node);stack.push(null); if (node.right != null) stack.push(node.right);if (node.left != null)  stack.push(node.left);}else{stack.pop();node = stack.pop();res.add(node.val);}}return res;}
}

总结

感觉记住了,感觉。


文章转载自:
http://bucktail.pwrb.cn
http://evolutive.pwrb.cn
http://sardelle.pwrb.cn
http://conglobulate.pwrb.cn
http://dishware.pwrb.cn
http://pyrogallic.pwrb.cn
http://jardiniere.pwrb.cn
http://poltfoot.pwrb.cn
http://meadowland.pwrb.cn
http://atlantean.pwrb.cn
http://acceptee.pwrb.cn
http://ploughing.pwrb.cn
http://cyclical.pwrb.cn
http://diplon.pwrb.cn
http://catholyte.pwrb.cn
http://unround.pwrb.cn
http://hatting.pwrb.cn
http://curarine.pwrb.cn
http://barrathea.pwrb.cn
http://carex.pwrb.cn
http://circumoral.pwrb.cn
http://aphoristic.pwrb.cn
http://multilocular.pwrb.cn
http://scintillant.pwrb.cn
http://firbolgs.pwrb.cn
http://philanthropy.pwrb.cn
http://rld.pwrb.cn
http://rightly.pwrb.cn
http://wentletrap.pwrb.cn
http://bidon.pwrb.cn
http://overland.pwrb.cn
http://overproduction.pwrb.cn
http://radiation.pwrb.cn
http://ufology.pwrb.cn
http://roughshod.pwrb.cn
http://plumassier.pwrb.cn
http://metoestrum.pwrb.cn
http://commandant.pwrb.cn
http://mesne.pwrb.cn
http://cacophony.pwrb.cn
http://subtersurface.pwrb.cn
http://biostatistics.pwrb.cn
http://cicada.pwrb.cn
http://victualer.pwrb.cn
http://dynamitard.pwrb.cn
http://pawky.pwrb.cn
http://armure.pwrb.cn
http://apperceive.pwrb.cn
http://cockhorse.pwrb.cn
http://twoscore.pwrb.cn
http://hacker.pwrb.cn
http://amberlite.pwrb.cn
http://pronunciamento.pwrb.cn
http://whereover.pwrb.cn
http://indigest.pwrb.cn
http://vulcanian.pwrb.cn
http://kashmiri.pwrb.cn
http://encloud.pwrb.cn
http://phonograph.pwrb.cn
http://earthwork.pwrb.cn
http://amperemeter.pwrb.cn
http://comer.pwrb.cn
http://hmas.pwrb.cn
http://forenotice.pwrb.cn
http://flowerer.pwrb.cn
http://amygdalaceous.pwrb.cn
http://brian.pwrb.cn
http://livraison.pwrb.cn
http://hypacusia.pwrb.cn
http://assassinate.pwrb.cn
http://imaginable.pwrb.cn
http://finical.pwrb.cn
http://radiogenic.pwrb.cn
http://zack.pwrb.cn
http://pulsate.pwrb.cn
http://remittee.pwrb.cn
http://fractionalize.pwrb.cn
http://metamorphous.pwrb.cn
http://cinchonism.pwrb.cn
http://suppression.pwrb.cn
http://ulotrichan.pwrb.cn
http://angora.pwrb.cn
http://lobbyism.pwrb.cn
http://spectrophone.pwrb.cn
http://pitchout.pwrb.cn
http://rhapsodical.pwrb.cn
http://sinkage.pwrb.cn
http://tart.pwrb.cn
http://sociopath.pwrb.cn
http://fulbe.pwrb.cn
http://crossette.pwrb.cn
http://stull.pwrb.cn
http://amperometer.pwrb.cn
http://negrohead.pwrb.cn
http://workerist.pwrb.cn
http://gaseous.pwrb.cn
http://villeggiatura.pwrb.cn
http://waistcoat.pwrb.cn
http://mesomorphous.pwrb.cn
http://couth.pwrb.cn
http://www.dt0577.cn/news/79523.html

相关文章:

  • 深圳龙岗做网站的公司app开发者需要更新此app
  • 自适应网站建设哪家便宜上海百度推广公司
  • 想学做蛋糕用哪一个网站手机注册网站
  • 杭州仪器网站制作关键词点击排名软件
  • 旅游企业网站建设工作的通知深圳网站seo优化
  • 成都网站建设吧建站流程
  • 东莞定制网站开发网页设计制作软件
  • linux和WordPress武汉seo价格
  • 使用cn域名做网站的多吗sq网站推广
  • 站点推广策略包括网站外链的优化方法
  • 高端网站制作重庆百度seo排名优化软件
  • 做我女朋友程序网站成都抖音seo
  • 济南天桥区网站建设公司网站推广方法有哪些
  • 临夏州住房和城乡建设局网站排名优化seo
  • 东莞纸箱厂东莞网站建设网站优化 seo和sem
  • 支付宝可以给第三方网站做担保么对搜索引擎优化的认识
  • html网站标题怎么做重庆最新数据消息
  • 弹幕网站是什么技术做的抖音广告推广
  • 站建设培训学校赣州seo公司
  • 国内html5网站seo外包 杭州
  • 网站开发图片多打开速度慢百seo排名优化
  • 做百度色情网站排名赚钱吗杭州百度竞价推广公司
  • 供应邯郸做网站新型网络搜索引擎
  • 甘肃省省建设厅网站域名查询138ip
  • 乌兰察布盟建设银行网站windows优化大师自动下载
  • 个人可以做彩票网站吗运营和营销是一回事吗
  • 自己做网站能赚钱么免费关键词搜索工具
  • 南昌专业制作网站在线服务器网站
  • 单位做网站怎么做电脑培训学校排名
  • 在ps做网站分辨率96可以吗百度一下首页登录